Skip to content

Legend shows arrow from annotate #8236 #13034

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 29 commits into from

Conversation

Wojciech-Lange
Copy link

@Wojciech-Lange Wojciech-Lange commented Dec 21, 2018

PR Summary

Answer for #8236 issue. Legend automatically handles an arrow from annotate. In fact the code is a limited variant of #10688 . FancyArrowPatch and HandlerAnnotation added. There might be some relicts left from the wider solution (#10688).

Example code:

import matplotlib.pylab as plt
from matplotlib.patches import FancyArrowPatch
from matplotlib.legend_handler import HandlerAnnotation

fig, ax = plt.subplots(1)
ax.plot([0, 1], [0, 0], label='line1')
ax.plot([0, 1], [1, 1], label='line2')
ax.annotate("",
            xy=(0.3,1.0),
            xytext=(0.3,0.0),
            arrowprops={'arrowstyle':'<->', 'color':'C7' },
            label='distance')
ax.legend()

plt.show()

example

PR Checklist

  • Code is Flake 8 compliant
  • Example in examples folder
  • (probably) Documentation is sphinx and numpydoc compliant

Copy link
Member

@dstansby dstansby left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Thanks for submitting this PR! Overall it looks good, I have added a couple of comments for code style changes. There are also a couple of test failures that need fixing - let us know if you need any more help with that.


HandlerBase.__init__(self, **kwargs)

def create_artists(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could the call aruguments be on multiple lines, but with a maximum line length of 79 characters? (if that makes sense; like

def func(arg1, arg2, arg3, arg4,
         arg5)

handler = HandlerFancyArrowPatch()
handle = orig_handle.arrow_patch

return handler.create_artists(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above regarding the function arguments here.

@dstansby dstansby added this to the v3.1 milestone Dec 28, 2018
@@ -32,7 +32,8 @@
from matplotlib.cbook import silent_list, is_hashable, warn_deprecated
from matplotlib.font_manager import FontProperties
from matplotlib.lines import Line2D
from matplotlib.patches import Patch, Rectangle, Shadow, FancyBboxPatch
from matplotlib.patches import (Patch, Rectangle, Shadow, FancyBboxPatch,
FancyArrowPatch)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please align inside of the opening parenthesis.

# support parasite axes:
if hasattr(ax, 'parasites'):
for axx in ax.parasites:
handles_original += (axx.lines + axx.patches +
axx.collections + axx.containers)
axx.collections + axx.containers+ax.texts)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't that be axx.texts?

@jklymak jklymak added the stale label Feb 10, 2019
@jklymak jklymak modified the milestones: v3.1.0, unassigned Feb 10, 2019
@jklymak
Copy link
Member

jklymak commented Jul 16, 2019

@haloxxx this looks quite close, but it'd help if you addressed the comments above.

@Wojciech-Lange
Copy link
Author

@haloxxx this looks quite close, but it'd help if you addressed the comments above.

After these few months my request doesn't pass through checks. I've tried to apply all the suggestions, but I'm not sure if I can handle this by myself.

@jklymak
Copy link
Member

jklymak commented Jul 18, 2019

You have a syntax error. Presumably that is straightforward to fix. Did you try running your example script before pushing the new commits? 😉

@tacaswell
Copy link
Member

You may also need to rebase this on current master to pick up the fixes / changes to the doc build.

@tacaswell tacaswell modified the milestones: unassigned, v3.4.0 Oct 2, 2020
@QuLogic QuLogic modified the milestones: v3.4.0, v3.5.0 Jan 22, 2021
@jklymak jklymak marked this pull request as draft March 27, 2021 17:46
@QuLogic QuLogic modified the milestones: v3.5.0, v3.6.0 Aug 18, 2021
@timhoffm timhoffm modified the milestones: v3.6.0, unassigned Apr 30, 2022
@story645 story645 modified the milestones: unassigned, needs sorting Oct 6, 2022
@dstansby
Copy link
Member

dstansby commented Jan 6, 2024

I'm going to close this in favour of #23160, which is an updated version of this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants