这是一个可重现的代码:
import matplotlib.pyplot as plt
import numpy as np
data_list = [np.random.normal(0, 1, [10]) for i in range(50)]
data_it = iter(data_list)
fig_size = (12, 8)
num_subs = 30
num_imgs = len(data_list)
num_figs = num_imgs/num_subs + 1
fig_list = []
for i in xrange(num_figs):
fig = plt.figure(i, figsize=fig_size)
fig_list.append(fig)
for j in range(num_subs):
ax = fig.add_subplot(5, 6, j)
ax.tick_params(bottom='off', top='off', left='off', right='off',
labelbottom='off', labeltop='off', labelright='off', labelleft='off')
ax.plot(np.arange(10), data_it.next())
ax.set_title('look at this!')
但正如你在上面所看到的那样,我在图1的右下角一直有一个孤独的子情节。我无法找到导致这种情况发生的错误。有人可以指出我必须修复什么才能让figure1有一个很好的有序子图?提前谢谢!
答案 0 :(得分:0)
哦,我发现了问题:
子图的索引必须以1开头。如果你有0,这将使图形在图的右下角绘制一个子图。
换句话说,只需在for循环中向j添加1即可解决问题
无论如何,谢谢!