Skip to content

auto legend position changes upon saving the figure #7353

Closed
@anntzer

Description

@anntzer

2.0b4 and master

from matplotlib import pyplot as plt
import numpy as np

plt.rcdefaults()
np.random.seed(1)

plt.plot(*np.random.rand(2, 300), ".", label="some long legend")
plt.plot(*np.random.rand(2, 300), ".", label="other long legend")
plt.legend()
plt.savefig("/tmp/foo.png")
plt.show()

The displayed window puts the legend at the center top of the figure, but the saved image puts the legend at the bottom left.

By changing the seed one can get cases where the two legends do match each other. In that case, careful inspection of the images show that the legends have slightly different sizes, which make them overlap with different number of points depending on the corner in which they are tentatively placed by the autolocator -- this is what leads to them moving upon saving.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions