我想使用一个for loop
来迭代绘制各组gridspec
图的图形。我定义了一个gridspec
来给予我这个图:
我想做一个for loop
,在给定的nrows
,ncols
中重复这些图。也就是说,我可以指定在3行2列中做这些图,并获得:
以下是我目前为止的代码:
import matplotlib.pyplot as plt
from matplotlib import transforms
import numpy as np
from matplotlib.gridspec import GridSpec
filename = ['file1', 'file2', 'file3', 'file4', 'file5', 'file6', 'file7', 'file8', 'file9', 'file10']
graph_title = ['(a) Title1', '(b) Title2', '(c) Title3', '(d) Title4', '(e) Title5', '(f) Title6', '(g) Title7', '(h) Title8', '(i) Title9', '(j) Title10',]
# define subplot grid
def graph3plots(filename, graph_title):
fig = plt.figure(figsize=(3, 3))
gs = GridSpec(6,5, figure=fig)
ax2 = plt.subplot(gs.new_subplotspec((0, 0), rowspan=4))
ax3 = plt.subplot(gs.new_subplotspec((0, 1), rowspan=4, colspan=4))
ax4 = plt.subplot(gs.new_subplotspec((4, 1), colspan=4))
fig.suptitle(graph_title)
fig.subplots_adjust(wspace=0.35, hspace=0.25)
n = 0
for i in range(0,10):
fig.add_subplot(5,2,i+1)
graph3plots(filename[n], graph_title[n])
n += 1
plt.savefig(f'Total Plots.pdf')
plt.show()
1条答案
按热度按时间q7solyqu1#
更新
更新
I used this.(Made by Zach)