I am creating a couple of pdf plots with matplotlib which is composed of 400 subplots. Each one has only 5 data points. It takes 420 s on a good computer to save 5 pdf picture. Is there any way to optimize the code or it is just normal for matplotlib?
Portion of code for plotting:
plot_cnt = 1
for k in np.arange(K_min, K_max + 1):
for l in np.arange(L_min, L_max + 1):
ax = plt.subplot(grid[0], grid[1], plot_cnt)
plot_cnt += 1
plt.setp(ax, 'frame_on', False)
ax.set_ylim([-0.1, 1.1])
ax.set_xlabel('K={},L={}'.format(k, l), size=3)
ax.set_xlim([-0.1, 4.1])
ax.set_xticks([])
ax.set_yticks([])
ax.grid('off')
ax.plot(np.arange(5), (data['S1']['Azimuth'][:, k - 1, l + offset_l] +
data['S1']['Delta Speed'][:, k - 1, l + offset_l] +
data['S1']['Speed'][:, k - 1, l + offset_l]) / 3,
'r-o', ms=1, mew=0, mfc='r')
ax.plot(np.arange(5), data['S2'][case][:, k - 1, l + offset_l],
'b-o', ms=1, mew=0, mfc='b')
plt.savefig(os.path.join(os.getcwd(), 'plot-average.pdf'))
plt.clf()
print 'Final plot created.'
Final Picture:
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…