Skip to content

Constrained Layout tutorial needs some cleanup.... #12391

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jklymak opened this issue Oct 3, 2018 · 0 comments · Fixed by #12394
Closed

Constrained Layout tutorial needs some cleanup.... #12391

jklymak opened this issue Oct 3, 2018 · 0 comments · Fixed by #12394

Comments

@jklymak
Copy link
Member

jklymak commented Oct 3, 2018

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 = True
if 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 the matplotlib 3.0 documentation with wanttoprint = True but it gives an error AttributeError: 'Figure' object has no attribute 'do_constrained_layout'.

Assuming that what is meant here is set_constrained_layout, the problem is that the figure shown deviates from the one obtained via wanttoprint = False. So it seems it's not possible to show the figure after saving it?

Using the second code (the one with fig.legend()) everything works as expected.

In my eyes there are the following things to do:

  1. Correct the first code to be runnable and produce the expected outcome for both settings of wanttoprint on screen and as saved image.
  2. Explain the reasoning behind turning the legend in layout option first off then on etc.
  3. Add a savefig line to the second example to make is clear that this is to be understood parallel to the previous example.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant