8000 Constrained Layout tutorial needs some cleanup.... · Issue #12391 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content
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 = 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.

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

      0