另存为PDF而不是另存为PNG时,诸如背景阴影,线宽和字体大小之类的绘图功能会丢失。我希望它看起来像PNG版本,但要作为PDF以获得更好的图像分辨率。我正在使用Python 2.7。
我的代码:
fig, axes = plt.subplots(nrows=3, ncols=1, figsize=(10, 5)), sharex=True)
# SET A
axes[0].plot(daysA.loc[0].values, color=colours[0], lw=1.5, zorder=2)
axes[0].axvspan(0, 288, alpha=0.3, color='grey', hatch='/', zorder=1)
axes[0].axvspan(288, 576, alpha=0.3, color='grey', hatch='o', zorder=1)
axes[0].axvspan(576, 864, alpha=0.3, color='grey', hatch='-', zorder=1)
axes[0].set_ylabel('Label A')
# SET B
axes[1].plot(daysB.loc[0].values, color=colours[0], lw=1.5)
axes[1].axvspan(0, 288, alpha=0.3, color='grey', hatch='/')
axes[1].axvspan(288, 576, alpha=0.3, color='grey', hatch='o')
axes[1].axvspan(576, 864, alpha=0.3, color='grey', hatch='-')
axes[1].set_ylabel('Label B')
# SET C
axes[2].plot(dayC.loc[0].values, color=colours[0], lw=1.5)
axes[2].axvspan(0, 288, alpha=0.3, color='grey', hatch='/')
axes[2].axvspan(288, 576, alpha=0.3, color='grey', hatch='o')
axes[2].axvspan(576, 864, alpha=0.3, color='grey', hatch='-')
axes[2].set_ylabel('Label C')
for ax in axes:
ax.tick_params(axis='both', which='major', labelsize=10)
ax.tick_params(axis='both', which='minor', labelsize=8)
start, end = ax.get_ylim()
stepsize = (end - start) / 4
ax.yaxis.set_ticks(np.arange(start, end, stepsize))
plt.xticks(range(0, 864, 72), ['00:00', '12:00', '00:00', '12:00', '00:00', '12:00',
'00:00', '12:00', '00:00', '12:00', '00:00', '12:00'],
rotation=45, fontsize=12)
plt.xlabel('Time of day')
plt.xlim(0, 864)
plt.subplots_adjust(hspace=0, bottom=0.22)
plt.setp([a.get_xticklabels() for a in fig.axes[:-1]], visible=False)
plt.savefig('/Users/ME/Desktop/PosterPlots/pdfexample.pdf')
plt.savefig('/Users/ME/Desktop/PosterPlots/pngexample.png')
plt.show()
可能是什么原因导致的,我该如何解决?
我尝试按照建议的here使用zorder
。这没有用,尽管我可能使用不正确。