在多个图中更改字幕

时间:2013-11-28 12:54:39

标签: python matplotlib plot subtitle

我得到相同的缩放和相同的字幕。这不是我想要的。如何重置字幕和缩放?

plt.imshow(grid1, extent=(x1.min(), x1.max(), y1.min(), y1.max()), origin='lower',  
           aspect='auto', interpolation='nearest', cmap=cm.gist_rainbow)      
fig1 = plt.gcf()
fig1.suptitle('Effectualness_etta of %s and %s' % (waveform1, waveform2))
plt.colorbar()
plt.draw()
fig1.savefig('/home/saeed/pycbc/test/plots/TDFD_Effectualness_etta_%s_%s.pdf'
             % (waveform1, waveform2), dpi=100)

plt.imshow(grid3, extent=(x3.min(), x3.max(), y3.min(), y3.max()), origin='lower',
           aspect='auto', interpolation='nearest', cmap=cm.gist_rainbow)
fig3 = plt.gcf()
fig3.suptitle('Effectualness_mo_M_chirp of %s and %s' % (waveform1, waveform2))
fig3.savefig('/home/saeed/pycbc/test/plots/TDFD_Real_Effectualness_mo_%s_%s.pdf'
              % (waveform1, waveform2), dpi=100)

plt.imshow(grid2, extent=(x2.min(), x2.max(), y2.min(), y2.max()), origin='lower', 
           aspect='auto', interpolation='nearest', cmap=cm.gist_rainbow)
fig2 = plt.gcf()
fig2.suptitle('Effectualness_M_chirp of %s and %s' % (waveform1, waveform2))
fig2.savefig('/home/saeed/pycbc/test/plots/TDFD_Effectualness_Mchirp_%s_%s.pdf'
             % (waveform1, waveform2), dpi=100)

2 个答案:

答案 0 :(得分:1)

每个块后必须有plt.close()以避免过度绘图。

答案 1 :(得分:0)

for (grid, x, y, subtitle_str, save_path_str) in zip([grid1, grid2, grid3],
                                                     [x1, x2, x3], [y1, y2, y3], 
                                                     list_of_titles, list_of_paths)):    
    fig, ax = plt.subplots()
    im = ax.imshow(grid, extent=(x.min(), x.max(), y.min(), y.max()), origin='lower',  
               aspect='auto', interpolation='nearest', cmap=cm.gist_rainbow)      
    fig.suptitle(suptitle_str)
    # or
    # ax.set_title(suptitle_str)
    fig.colorbar(im)
    fig.savefig(save_path_str, dpi=100)

作为旁注,如果图中只有一个轴,则可以使用轴标题。