-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
FancyArrowPatch path is changed when added to an axis #8694
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
Comments
The problem is your expectation. The path of a FancyArrowPatch in data coordinates depends on the transform, which is not known until it is attached to an Axes. Here is the method: def get_path(self):
"""
Return the path of the arrow in the data coordinates. Use
get_path_in_displaycoord() method to retrieve the arrow path
in display coordinates.
"""
_path, fillable = self.get_path_in_displaycoord()
if cbook.iterable(fillable):
_path = concatenate_paths(_path)
return self.get_transform().inverted().transform_path(_path) This is calling |
I agree that Extracting the path before plotting the arrow works fine, but simple adding the import matplotlib.pyplot as plt
import matplotlib.patches as mpatch
# Create simple arrow
arrowstyle = mpatch.ArrowStyle.Simple(head_length=0.2, head_width=0.2, tail_width=0.1)
arrow = mpatch.FancyArrowPatch((0.5, 0), (0.5, 1), arrowstyle=arrowstyle)
# Extract the path of the arrow
path = arrow.get_path()
pathpatch = mpatch.PathPatch(path)
fig, [ax1, ax2] = plt.subplots(2, 1, tight_layout=True)
ax1.add_artist(arrow)
ax2.add_artist(pathpatch)
ax1.set_title('FancyArrowPatch')
ax2.set_title('Path before adding FancyArrowPatch to ax1')
plt.show() |
I don't understand why this is bothering you. What is the problem you are trying to solve? |
@efiring, what other artist behaves like this?
…On Thu, Jun 1, 2017 at 4:38 PM, Eric Firing ***@***.***> wrote:
I don't understand why this is bothering you. What is the problem you are
trying to solve?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#8694 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AARy-OLkI6MDQPXLeOjSA9mxMt_gvOQKks5r_yFAgaJpZM4NsPzj>
.
|
If I ask Matplotlib to draw an arrow with a head_width of 0.2, I expect the
head_width to be 0.2. At the very least the documentation should explain
how the width gets from 0.2 to whatever it is in the second plot.
On 1 Jun 2017 9:38 pm, "Eric Firing" <notifications@github.com> wrote:
I don't understand why this is bothering you. What is the problem you are
trying to solve?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#8694 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AF6RfInD6ZtRhYAoT5CMFrW7yqpkkR1Hks5r_yFJgaJpZM4NsPzj>
.
|
(sorry, replying via email so got a bit mixed up, I meant first plot in the
comment above)
…On 1 Jun 2017 9:54 pm, "David Stansby" ***@***.***> wrote:
If I ask Matplotlib to draw an arrow with a head_width of 0.2, I expect
the head_width to be 0.2. At the very least the documentation should
explain how the width gets from 0.2 to whatever it is in the second plot.
On 1 Jun 2017 9:38 pm, "Eric Firing" ***@***.***> wrote:
I don't understand why this is bothering you. What is the problem you are
trying to solve?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#8694 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AF6RfInD6ZtRhYAoT5CMFrW7yqpkkR1Hks5r_yFJgaJpZM4NsPzj>
.
|
The "Fancy" things and their derivatives, annotations, are extremely complex, hard to understand (at least for me), and poorly documented. But they work, and serve important functions. So you seem to be pointing to an oddity, something calling for better documentation, not a bug. Correct? I still don't understand how you stumbled across this. Is it that you were trying to figure out what the units of the arrow parameters are? Regarding units: I think your expectation of specifying arrow properties in data coordinates is not right; the point of these sorts of things is that they inherently use a mix of coordinate systems and units. For example, you may want an arrow to connect two points specified in data coordinates, but normally one wants the arrow characteristics other than length to be in some sort of display coordinates and units, e.g. points or inches, or maybe pixels. If you have a chunk of time and the motivation, then going through the "Fancy" code, figuring out how it all works, and documenting that along with what all of the kwargs really mean and do, would be a great contribution. The code was written quite some time ago by Jae-Joon Lee, and we are very grateful to him for that, but he has completely dropped out of sight as far as mpl is concerned. |
I stumbled across this in my attempts to clean up arrow plotting as a whole in Matplotlib. In order to deprecate What I broadly intend on doing in the long run is sketched out here, which is definitely open to discussion and comment: https://github.com/matplotlib/matplotlib/wiki/MEP-29-(arrows). re. a mixture of display and data co-ordiante systems, I kind of understand the point, but think it's a bit confusing. I also think (but may be wrong) that the concept of 'data space' is much more intuitive to an average user, and specifying all the arrow properties in the same units (data units) is much less confusing than some in 'data units' (arrow start, arrow end), and some in 'display units' (arrow head properties). Given the plan is to use |
It turns out that the head doesn't change shape in display co-ordinates, so I have crossed out my false statement in the above comment. |
Bug report
Adding a
FancyArrowPatch
to an axis changes the result returned byget_path()
. I would expect adding an artist to an axis to have no effect on its path in data co-ordinates.Code for reproduction
Actual outcome
Expected outcome
Clearly the two paths are different - I expected them to be the same (and I would expect the first one to be the correct one based on the
FancyArrowPatch
docstring).Matplotlib version
The text was updated successfully, but these errors were encountered: