-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Annotation legend #8292
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
Annotation legend #8292
Conversation
lib/matplotlib/legend_handler.py
Outdated
|
||
class HandlerAnnotation(HandlerBase): | ||
""" | ||
Handler for FancyArrowPatch instances. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FancyArrowPatch <- Annotation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed!
I forgot to ping you @bendichter @tacaswell I am not sure what should be displayed when an annotation has no text and no arrow. I used a white Rectangle but this still looks awkward, would it be better (and possible?) to remove the legend entry in this case? |
I wonder how useful it would be to make keyword arguments for the default replacement string for long text, and the maximal length of text entries (nice and clever names would have to be found…). The use case I could see is a user that would want to deviate from the default values (e.g. from "a" for strings longer than 1 char to "Aa" for strings longer than 2 chars) without having to override the whole plt.legend(handler_map={my_annotation: HandlerAnnotation(rep_str='Aa', str_maxlen=2)}) |
This looks beautiful! About the white rectangle, I can't think of a use case where you would have an annotation with no text and no arrow in the first place. I kind of liked having the white rectangle there because now I could imagine using it as a hack to give the legend subtitles. |
@bendichter Ok! I made the rectangle transparent to make sure it is not visible even if something is below the legend @afvincent Good point, I added these arguments and updated the example in the first comment. I also prefer 'Aa', which conveys the idea of 'some text' better than 'a' so I made it the default. |
@jlecoeur Any update on this? |
@tacaswell I would say it is done. Details like the relative size of character and arrow, or which character to use to represent long strings can be discussed, but the main thing is done and functional |
"power cycled" to restart CI against current master. |
@tacaswell Many Ci fails 👎 I do not have time to fix them at the moment, can you have a shot at it? Otherwise I will come back to it, but that would not be before a month from now. |
Look forward to hearing from you in a month! |
I'll take care of this for you! |
Closing in lieu of the active, but not merged, #10688 |
Fixes #8236
I added new legend handlers for Text, FancyArrowPatch and Annotation artists (HandlerText, HandlerFancyArrowPatch and HandlerAnnotation).
HandlerAnnotation can draw different artists in the legend:
In HandlerTuple, I added the possibility of different width ratios for the artists. HandlerAnnotation uses a width_ratios=[1,4] (ie. the arrow is 4 times wider than the text).
Example code:
output:
