Skip to content

Instantly share code, notes, and snippets.

@tkshnkmr
Created November 30, 2019 16:01
Show Gist options
  • Save tkshnkmr/506d70425ba89370458b5df33172750f to your computer and use it in GitHub Desktop.
Save tkshnkmr/506d70425ba89370458b5df33172750f to your computer and use it in GitHub Desktop.
import numpy as np
import matplotlib.pyplot as plt
# Input x, output y
x = np.linspace(0, 2*np.pi, 400)
y = np.sin(x**2)
# make multiple subplots.
# you can define the size of figure and dpi (dot per inch, defalt dpi=72)
my_dpi = 50
fig, axes = plt.subplots(nrows=3, ncols=2, figsize=(10, 10), dpi=my_dpi)
print(fig)
print(axes)
# title for entire figure
fig.suptitle('Subplot ex2: Define subplots first', fontsize=20)
# edit subplots
axes[0, 1].set_title('Subplot 1', fontsize=14)
axes[2, 1].plot(x, y)
axes[2, 1].set_xlabel('X input', fontsize=14)
axes[2, 1].set_title('Subplot 5', fontsize=14)
# Save figure
fig.savefig('Subplot_ex2.png')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment