FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Legend with "loc=best" does not try to avoid text · Issue #23323 · matplotlib/matplotlib · GitHub

Repository navigation

Legend with "loc=best" does not try to avoid text #23323

Closed

Description

I had this issue, and found almost exactly the same problem on Stack Overflow (link)

Briefly, the pyplot.legend does not try to avoid pyplot.text. Here is a minimal example:

import matplotlib.pyplot as plt
x = [1, 2]
plt.plot(x, x, label='plot name')
plt.gca().text(0.05, 0.95, 'some text', transform=plt.gca().transAxes, verticalalignment='top')
plt.gca().legend(loc='best')
plt.show()

resulting in legend overlaying the text like this:

BTW, my matplotlib version is 3.4.3

Activity

  1. jklymak commented on Jun 22, 2022

    Member

    It maybe doesn't unwind the transform to put it in data units instead of transAxes?

  2. ym3141 commented on Jun 22, 2022

    Author

    It maybe doesn't unwind the transform to put it in data units instead of transAxes?

    Nope, got the same issue with the following code:

    import matplotlib.pyplot as plt
    x = [1, 2]
    plt.plot(x, x, label='plot name')
    plt.gca().text(1.05, 2, 'some text', verticalalignment='top')
    plt.gca().legend(loc='best')
    plt.show()
    
  3. jklymak commented on Jun 22, 2022

    Member

    Yes, indeed texts are not considered.

    def _auto_legend_data(self):

  4. added this to the v3.9.0 milestone on Jan 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL