Matplotlibで綺麗にグラフを並べる方法
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
# figure()でグラフを表示する領域をつくり,figというオブジェクトにする.
fig = plt.figure(dpi=150)
# plt.subplots_adjust(wspace=0.4, hspace=0.4)
h = 5
v = 10
height = 16
width = 16
axes = []
for i in range(h * v):
b = np.random.randint(7, size=(height, width))
axes.append(fig.add_subplot(v, h, i + 1))
subplot_title = f"{str(i)}"
axes[-1].set_ylabel(subplot_title)
axes[-1].axes.yaxis.set_ticks([])
axes[-1].axes.xaxis.set_visible(False)
# axes[-1].axes.yaxis.set_visible(False)
plt.imshow(b)
plt.tight_layout() # 追加
plt.show()
この記事が気に入ったらサポートをしてみませんか?