2013-12-09 150 views
0

因此,我试图保存for循环的每次迭代后生成的多个图,我想插入一个名称标记像迭代完成数量的标题像头。代码看起来像这样。我尝试了suptitle,但它不起作用。Python的matplotlib插入索引的阴谋

for i in range(steps): 

     nor_m = matplotlib.colors.Normalize(vmin = 0, vmax = 1) 
     plt.hexbin(xxx,yyy,C, gridsize=13, cmap=matplotlib.cm.rainbow, norm=nor_m, edgecolors= 'k', extent=[-1,12,-1,12]) 
     plt.draw() 
     plt.suptitle('frame'%i, fontsize=12) 
     savefig("flie%d.png"%i) 

回答

1

plt.title怎么样?

for i in range(steps): 

    nor_m = matplotlib.colors.Normalize(vmin=0, vmax=1) 
    plt.hexbin(xxx, yyy, C, gridsize=13, cmap=matplotlib.cm.rainbow, norm=nor_m, edgecolors= 'k', extent=[-1,12,-1,12]) 
    plt.title('frame %d'%i, fontsize=12) 
    plt.savefig("flie%d.png"%i) 

您在标题调用的字符串格式中也有错误。实际上'frame'%i应该已经失败,出现TypeError: not all arguments converted during string formatting-错误。 另请注意,您不需要plt.draw,因为这将被plt.savefig调用。