Skip to content

Legend annotation #10802

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
wants to merge 6 commits into from
Closed

Conversation

SwarnaD
Copy link

@SwarnaD SwarnaD commented Mar 15, 2018

PR Summary

Annotations are now handled in the legend.

  • no text, no arrow results in a blank space (rectangle)
  • text, no arrow results in the text being replicated as a legend item that is cropped off within the space it fits
  • text/no text, arrow results in the arrow being replicated into the legend

This was intended to implement #8236

Raw Text and arrows are not handled by the legend.

Example

image

import matplotlib.pyplot as plt

fig, ax = plt.subplots(1)
ax.plot([0, 1], [0, 0], label='line1')
ax.plot([0, 1], [1, 1], label='line2')

#no arrow, short text
my_annotation = ax.annotate("test",
            xy=(0.2,0.6),
            xytext=(0.2,0.6),
            color='k',
            label='no arrow, short text')

#no arrow, long text
my_annotation = ax.annotate("testtestest",
            xy=(0.2,0.5),
            xytext=(0.2,0.5),
            color='m',
            label='no arrow, long text')

#dashed arrow, no text
ax.annotate("",
            xy=(0.6,0.8),
            xytext=(0.2,0.8),
            arrowprops={'arrowstyle':'<-', 'ls':'dashed', 'color':'r' },
            label='dashed, no text')

#solid arrow, no text
ax.annotate("",
            xy=(0.6,0.7),
            xytext=(0.2,0.7),
            arrowprops={'arrowstyle':'<-', 'color':'b' },
            label='solid, no text')

#arrow and text
ax.annotate("test",
            xy=(0.6,0.9),
            xytext=(0.2,0.9),
            arrowprops={'arrowstyle':'<->', 'color':'g' },
            label='arrow + text')
ax.legend()

plt.grid()
plt.show()

PR Checklist

  • Has Pytest style unit tests
  • Code is PEP 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

@jklymak
Copy link
Member

jklymak commented Mar 15, 2018

What’s unique in this versus #10688?

@SwarnaD
Copy link
Author

SwarnaD commented Mar 15, 2018

As opposed to that one, our solution:

  • Strict improvement:

    • respects the linestyle property of arrows (dashes, etc.) vs. not doing so
  • Design differences:

    • crops Text items off when they extend too long vs. replacing their string with "Aa"
    • does not legend Texts and arrows not part of annotations vs. adding them to legend by default
    • legends text+arrow Annotations with arrows only vs. legending them both in
    • arrows seem to look a little different in proportions, ours are more filling and wide

@jklymak
Copy link
Member

jklymak commented Mar 15, 2018

Thanks so much for the PR.

However, since this totally overlaps a previous PR that the previous author has put a lot of good faith effort into, I'm going to close. (This says nothing about the relative merits of the two PRs).

If you want to move this forward, you can work with the author of #10688, you can ask them to close their PR in lieu of yours (and then we can re-open this), and/or you can submit a new PR once their work has been accepted.

In the future, you can check if someone has started working on an Issue by looking for PRs that link to the issue.

Other devs are certainly welcome to override this decision!

@jklymak jklymak closed this Mar 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants