You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Arc patch ignoring theta1/theta2 when added to Axes via PatchCollection #11266
With matplotlib=2.1.2, when I add an Arc patch to an Axes instance via a PatchCollection, the arc always appear as a complete ellipse, regardless of values I set for theta1 and theta2. When I add the Arc directly via Axes.add_patch, I don't have this problem.
Last time I checked (matplotlib 1.4.0), this wasn't an issue. I haven't bisected to figure out when the problem started.
The problem is that the Arcis essentially an Ellipse; it just has two additional attributes theta1 and theta2 and a completely different draw method. So the Arc only becomes an arc at drawtime.
The PatchCollection does not use the individual patches' draw method, but its own (which draws the paths of the patches).
Possibly it's easier to find a sufficient workaround for this problem than to create a new PatchCollectionWhichAllowsForArcs. @dyf What is the motivation to use a PatchCollection instead adding the arcs individually?
I can certainly add the patches individually. I used a pattern in my code where I create a collection of elements and style them all at once via a PatchCollection, e.g.:
but I can just as easily do this in a loop if that's the current preferred route. Not a big deal.
That said, I wanted to let y'all know that a) this used to work, and b) I think the current behavior is surprising. If you need/want to keep it this way, you might want to update the docs.
This line was removed in #8047 (on 11 Mar 2017). Not sure how it can have been removed before the release but still be in it?!
In any case, reintroducing this line into master will indeed produce arcs instead of ellipses in a PatchCollection; however the bug that #8047 fixed (or at least some other problem that produces wrong arc length) would be reintroduced into the code base.
attn: @dstansby who removed this line in question and @tacaswell who confirmed that "pushing this down into Path.arc is not right".
Does putting that line back in fix this problem, and pass all the tests? Might be worth trying. (sorry, I don't have time to look at this at the moment 😦 )
To be more precise here, I'm considering the following code which should add an Arc between theta1=0 and theta2=60 as a standalone patch as well as inside a PatchCollection.
I think we can just move the logic in the diff for #8047 into into the init rather than the draw. I can’t really think why this would have to be done at draw time, but maybe I’ve not thought it through.
There are two reasons the arc is calculated at drawtime and not in the __init__:
Efficiency: Only calculate the points to draw once it is clear where to draw them.
Units: Only calculate the points once the arc is given an axes with units to live in.
I think it would be possible to sacrifice efficiency (1) and let the total arc be calculated at init; but I have no idea how to do that as long as it's not in an axes (2). I think this second point is what @dstansby stumbled upon when doing the fix, so I thought he might be able to tell a bit more on the reasoning here.
Well, units + PatchCollections bite us again.... This should stay open as something the units MEP should address: How can we pre-specify patches when the final axes will have units?
Activity
ImportanceOfBeingErnest commentedon May 18, 2018
The problem is that the
Arcis essentially anEllipse; it just has two additional attributestheta1andtheta2and a completely differentdrawmethod. So theArconly becomes an arc at drawtime.The
PatchCollectiondoes not use the individual patches'drawmethod, but its own (which draws the paths of the patches).Possibly it's easier to find a sufficient workaround for this problem than to create a new
PatchCollectionWhichAllowsForArcs.@dyf What is the motivation to use a
PatchCollectioninstead adding the arcs individually?dyf commentedon May 18, 2018
@ImportanceOfBeingErnest Thanks for the quick response.
I can certainly add the patches individually. I used a pattern in my code where I create a collection of elements and style them all at once via a
PatchCollection, e.g.:https://github.com/AllenInstitute/AllenSDK/blob/master/allensdk/brain_observatory/circle_plots.py#L574
but I can just as easily do this in a loop if that's the current preferred route. Not a big deal.
That said, I wanted to let y'all know that a) this used to work, and b) I think the current behavior is surprising. If you need/want to keep it this way, you might want to update the docs.
Thanks!
jklymak commentedon May 18, 2018
I think it’s worth chasing down why it changed.
ImportanceOfBeingErnest commentedon May 19, 2018
You're right. My explanation comes short of explaining the issue. The code works as expected in matplotlib 2.0.2.
Version 2.0.2 (released on 5 May 2017) contains the line:
matplotlib/lib/matplotlib/patches.py
Line 1561 in e175a41
This line was removed in #8047 (on 11 Mar 2017). Not sure how it can have been removed before the release but still be in it?!
In any case, reintroducing this line into master will indeed produce arcs instead of ellipses in a PatchCollection; however the bug that #8047 fixed (or at least some other problem that produces wrong arc length) would be reintroduced into the code base.
attn: @dstansby who removed this line in question and @tacaswell who confirmed that "pushing this down into Path.arc is not right".
dstansby commentedon May 21, 2018
Does putting that line back in fix this problem, and pass all the tests? Might be worth trying. (sorry, I don't have time to look at this at the moment 😦 )
ImportanceOfBeingErnest commentedon May 21, 2018
I did not run any tests, but as said, simply putting
self._path = Path.arc(self.theta1, self.theta2)back into the__init__has two effects:ImportanceOfBeingErnest commentedon May 22, 2018
To be more precise here, I'm considering the following code which should add an Arc between
theta1=0andtheta2=60as a standalone patch as well as inside aPatchCollection.Full code here
Full Code:I'm running this code in several versions:
Matplotlib 2.0.2
Arccan be used in aPatchCollection.Arcas well asArcinside collection have the wrong angle.Matplotlib 2.2.2
after fix #8047
Arccannot be used in aPatchCollection.Archas the correct angle.Matplotlib development version + added
self._pathin__init__Adding the line
matplotlib/lib/matplotlib/patches.py
Line 1561 in e175a41
back into master produces:
Arcused in aPatchCollectionhas the wrong angle.Archas the correct angle.jklymak commentedon May 22, 2018
I think we can just move the logic in the diff for #8047 into into the init rather than the draw. I can’t really think why this would have to be done at draw time, but maybe I’ve not thought it through.
ImportanceOfBeingErnest commentedon May 22, 2018
There are two reasons the arc is calculated at drawtime and not in the
__init__:I think it would be possible to sacrifice efficiency (1) and let the total arc be calculated at init; but I have no idea how to do that as long as it's not in an axes (2). I think this second point is what @dstansby stumbled upon when doing the fix, so I thought he might be able to tell a bit more on the reasoning here.
jklymak commentedon May 22, 2018
Well, units +
PatchCollectionsbite us again.... This should stay open as something the units MEP should address: How can we pre-specify patches when the final axes will have units?chibai commentedon Jan 20, 2022
Is this bug fixed?
The version of Matplotlib is 3.5.1 now~
timhoffm commentedon Jan 25, 2022
No, it's unchanged. This is a fundamental design problem, which nobody has taken the effort to dive into and find a solution.