Created
January 15, 2023 11:47
-
-
Save cobanov/268aeba78ddf5bbd62bd59376e7f812b to your computer and use it in GitHub Desktop.
Simple subplot using matplotlib
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import matplotlib.pyplot as plt | |
# Data | |
x = np.random.randn(20) | |
y = 3 * x + 0.2 + np.random.randn(20) * 0.3 | |
# Subplot | |
fig, axs = plt.subplots(1, 2, figsize=(10, 4)) | |
fig.suptitle("Comparison") | |
# axs0 | |
axs[0].scatter(x, y) | |
axs[0].plot(x, 0.1 * x + 2.6, label="y1 = 0.1x + 2.6", c="orange") | |
axs[0].set_title("Untrained") | |
axs[0].legend() | |
# axs1 | |
axs[1].scatter(x, y) | |
axs[1].plot(x, 2 * x + 0.5, label="y2 = 2*x + 0.5", c="orange") | |
axs[1].set_title("Trained") | |
axs[1].legend() | |
# Show | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment