** Be careful not to confuse subplot with subplots **
import numpy as np
import matplotlib.pyplot as plt
plt.style.use('seaborn-whitegrid')
%matplotlib inline
#Prepare the data
t = np.linspace(-np.pi, np.pi, 1000)
x1 = np.sin(2*t)
x2 = np.cos(2*t)
x3 = np.tan(2*t)
x4 = 1 / x1
x5 = 1 / x2
x6 = 1 / x3
-(Example 1) Plot 6 data in 2 rows and 3 columns
fig, axes = plt.subplots(2, 3, figsize=(16,12))
l = [[x1, x2, x3], [x4, x5, x6]]
for i in range(2):
for j in range(3):
axes[i][j].plot(t, l[i][j])
axes[i][j].set_xlim(-np.pi, np.pi)
axes[i][j].set_ylim(-1, 1)
-(Example 2) Plot 6 data in 3 rows and 2 columns
fig, axes = plt.subplots(3, 2, figsize=(8,12))
l = [[x1, x2], [x3, x4], [x5, x6]]
for i in range(3):
for j in range(2):
axes[i][j].plot(t, l[i][j], color='r')
axes[i][j].set_xlim(-np.pi, np.pi)
axes[i][j].set_ylim(-1, 1)
--The first and second arguments of subplots are the rows and columns of the graph. --fig size is the size per graph (inch) --Use axes and l (list of data you want to visualize) as if you were slicing
Recommended Posts