-1

I am plotting a graph in my jupyter notebook like this:

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()

And the output looks like this:

enter image description here

Once i save.fig the plot, the legends gets squeezed into the plot and the name cut off (it is obviously too long, i know)

enter image description here

Can i somehow control the saved plot and how could i better place the legends without it hiding information of the plot?

2
  • 2
    fig.savefig("name.pdf", bbox_inches="tight") gives a similar figure than the one shown in the notebook. Commented Nov 24, 2019 at 0:10
  • Agree with @ImportanceOfBeingErnest, looks identical to me. (Output). Commented Nov 24, 2019 at 0:15

1 Answer 1

-1

As "ImportanceOfBeingErnest" pointed out in the comments, adding bbox_inches="tight" as parameter to the savefig function, solves the problem.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.