Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Closed
@jklymak

Description

@jklymak

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:

  1. Correct the first code to be runnable and produce the expected outcome for both settings ofwanttoprint 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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp