Skip to content

Instantly share code, notes, and snippets.

@tkshnkmr
Created November 30, 2019 16:09
Show Gist options
  • Save tkshnkmr/c412b3795b2671c831686272a65d2f20 to your computer and use it in GitHub Desktop.
Save tkshnkmr/c412b3795b2671c831686272a65d2f20 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)
# Creates figure first
my_dpi = 200
fig = plt.figure(figsize=(4, 2), dpi=my_dpi)
print(fig)
fig.suptitle('Subplot ex3-2: Add subplot later')
# Add plot
ax1 = fig.add_subplot(1, 3, 1)
ax1.plot(x, y)
ax1.set_xlabel('X label, plot1')
ax1.set_ylabel('Y label, plot1')
ax1.set_xticklabels('')
ax1.set_yticklabels('')
# Add plot
ax2 = fig.add_subplot(1, 3, 2)
ax2.plot(x, y)
ax2.set_xlabel('X label, plot2')
ax2.set_ylabel('Y label, plot2')
# Add plot
ax3 = fig.add_subplot(1, 3, 3)
ax3.set_xlabel('X label, plot3')
ax3.set_ylabel('Y label, plot3')
fig.savefig('Subplot_ex4.png')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment