Skip to content

Instantly share code, notes, and snippets.

@ultimatile
Last active August 29, 2021 09:23
Show Gist options
  • Save ultimatile/8cb3f622adfbafc306bf2b05e49693bc to your computer and use it in GitHub Desktop.
Save ultimatile/8cb3f622adfbafc306bf2b05e49693bc to your computer and use it in GitHub Desktop.
縦vnum個×横hnum個のgraphをまとめて出力するpython script
#!/usr/bin/env python3
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.backends.backend_pdf import PdfPages
from numpy.random import randn
h = 18.4
fig = plt.figure(figsize=(h, 9 / 16 * h))
cmap = plt.get_cmap("gnuplot")
color = lambda a: cmap(float(a))
#plt.rcParams['font.family'] = 'sans-serif' #使用するフォント
plt.rcParams['xtick.direction'] = 'in'# x軸の目盛線が内向き('in')か外向き('out')か双方向か('inout')
plt.rcParams['ytick.direction'] = 'in'# y軸の目盛線が内向き('in')か外向き('out')か双方向か('inout')
plt.rcParams['xtick.major.width'] = 1.0 #x軸主目盛り線の線幅
plt.rcParams['ytick.major.width'] = 1.0 #y軸主目盛り線の線幅
plt.rcParams['font.size'] = 14
plt.rcParams['xtick.labelsize'] = 14
plt.rcParams['ytick.labelsize'] = 14 #フォントの大きさ
plt.rcParams['axes.linewidth'] = 1 # 軸の線幅edge linewidth。囲みの太さ
plot_linewidth = 2
N = 100
x = np.arange(N)
runs = 4
def ppp(ax, i):
for run in np.arange(runs):
ax.scatter(x, randn(N), marker="x", label=r"run {}".format(run + 1))
ax.grid(color='k', linestyle=':', linewidth=0.5, alpha=0.5)
ax.set_xlim(0, N)
vnum = 4
hnum = 6
num_sbplt = vnum * hnum
for i in np.arange(1, num_sbplt + 1):
ppp(fig.add_subplot(vnum, hnum, i), i)
fig.add_subplot(111, frameon=False)
plt.subplots_adjust(top=0.92, bottom=0.1, left=0.09, right=0.97, hspace=0.22, wspace=0.22)
plt.tick_params(labelcolor='none', top='off', bottom='off', left='off', right='off')
plt.grid(False)
plt.xlabel(r"$X$", size=30, labelpad=20)
plt.ylabel(r"$Y$", size=30, labelpad=20)
#plt.show()
pp = PdfPages('test{}{}.pdf'.format(vnum, hnum))
pp.savefig(fig)
pp.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment