Python 为什么matplotlib在jupyter笔记本中显示的绘图与导出为pdf时显示的绘图不同

Python 为什么matplotlib在jupyter笔记本中显示的绘图与导出为pdf时显示的绘图不同,python,matplotlib,jupyter-notebook,jupyter,Python,Matplotlib,Jupyter Notebook,Jupyter,我正在我的jupyter笔记本中绘制一个图形,如下所示: fig3, ax3 = plt.subplots() color = 'tab:red' ax3.set_xlabel('active learning cycles') ax3.set_ylabel('amount', color=color) ax3.plot(al_cycle_count, al_bbs_count, color=color) ax3.plot(al_cycle_count, ccs, color=color, d

我正在我的jupyter笔记本中绘制一个图形,如下所示:

fig3, ax3 = plt.subplots()

color = 'tab:red'
ax3.set_xlabel('active learning cycles')
ax3.set_ylabel('amount', color=color)
ax3.plot(al_cycle_count, al_bbs_count, color=color)
ax3.plot(al_cycle_count, ccs, color=color, dashes=[6, 2])
ax3.tick_params(axis='y', labelcolor=color)

ax4 = ax3.twinx()  # instantiate a second axes that shares the same x-axis

ax4.set_ylabel('% (1 = 100%)')
ax4.plot(al_cycle_count, precisions)
ax4.plot(al_cycle_count, recalls)
ax4.plot(al_cycle_count, f1s)

ax3.set(title='performance of "' + experiment_name + '"')
fig3.legend(['Bounding Boxen', 'Learning Steps', 'Precision', 'Recall', 'F1'], loc='upper right', bbox_to_anchor=(0.35, 0.9))

#fig3.tight_layout()  # otherwise the right y-label is slightly clipped
plt.show()
输出如下所示:

fig3, ax3 = plt.subplots()

color = 'tab:red'
ax3.set_xlabel('active learning cycles')
ax3.set_ylabel('amount', color=color)
ax3.plot(al_cycle_count, al_bbs_count, color=color)
ax3.plot(al_cycle_count, ccs, color=color, dashes=[6, 2])
ax3.tick_params(axis='y', labelcolor=color)

ax4 = ax3.twinx()  # instantiate a second axes that shares the same x-axis

ax4.set_ylabel('% (1 = 100%)')
ax4.plot(al_cycle_count, precisions)
ax4.plot(al_cycle_count, recalls)
ax4.plot(al_cycle_count, f1s)

ax3.set(title='performance of "' + experiment_name + '"')
fig3.legend(['Bounding Boxen', 'Learning Steps', 'Precision', 'Recall', 'F1'], loc='upper right', bbox_to_anchor=(0.35, 0.9))

#fig3.tight_layout()  # otherwise the right y-label is slightly clipped
plt.show()

一旦我保存了.fig的情节,传奇就被压缩到情节中,名字也被删掉了(我知道这显然太长了)


我能以某种方式控制保存的绘图吗?如何更好地放置图例而不隐藏绘图信息?

正如评论中指出的“ImportanceOfBeingErnest”,将bbox_inches=“tight”作为参数添加到savefig函数中,解决了问题。

fig.savefig(“name.pdf”,bbox_inches=“tight”)
给出的数字与笔记本中显示的数字相似。同意@ImportanceOfBeingErnest,看起来与我相同。().