Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Closed
Labels
Description
Originally posted by@ImportanceOfBeingErnest in#12377 (comment)
The code does not seem to be runnable and does not give a sensible result. I used this code
fig, axs = plt.subplots(2, 2, constrained_layout=True)for ax in axs.flatten()[:-1]: ax.plot(np.arange(10))axs[1, 1].plot(np.arange(10), label='This is a plot')leg = axs[1, 1].legend(loc='center left', bbox_to_anchor=(0.8, 0.5))leg.set_in_layout(False)wanttoprint = Trueif wanttoprint: leg.set_in_layout(True) fig.do_constrained_layout(False) fig.savefig('outname.png', bbox_inches='tight')plt.show()
i.e. the code from thematplotlib 3.0 documentation withwanttoprint = True
but it gives an errorAttributeError: 'Figure' object has no attribute 'do_constrained_layout'
.
Assuming that what is meant here isset_constrained_layout
, the problem is that the figure shown deviates from the one obtained viawanttoprint = False
. So it seems it's not possible to show the figure after saving it?
Using the second code (the one withfig.legend()
) everything works as expected.
In my eyes there are the following things to do:
- Correct the first code to be runnable and produce the expected outcome for both settings of
wanttoprint
on screen and as saved image. - Explain the reasoning behind turning the legend in layout option first off then on etc.
- Add a savefig line to the second example to make is clear that this is to be understood parallel to the previous example.