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
savefig messes up coordinate transformation of annotate #4375
Strangely enough, when commenting out the savefig, what is shown interactively on screen is the wrong version, until plt.draw() is called explicitely. After that, also savefig works correctly, so this is a workaround.
@adrn That sort of griping is not the most effective at making devs want to help you. Without seeing your code I suspect you are using display-space units at some point which you should not be doing. Please open a new issue or send a note to the mailing list.
@PiQuer Does this work reliably on any version of mpl? Trying to sort out if this is a regression or a long standing bug.
I suspect this issues is related to the use of the inset axes which has some non-trivial logic in how it's transforms get managed. The inset axes has it's transforms defined in terms of the transforms of the parent axes. Currently the details of those transforms get set up (somehow, have not traced the code path yet) as part of the draw process off the inset axes. When it is initialized it's transforms have some default value. The annotation in the above code is a child of the inset axes. The way the draw tree is worked is that the parent axes, then all it's children, then the inset axes, then all of it's children are drawn. The source of the error here is that the annotation is drawn before the inset axes is drawn, and hence before it's transforms have been updated to reflect that it is an inset axes. The simplest work around is to just make the annotation belong to the inset axes so it is always drawn after the transfroms have been properly updated:
I know this is rather old, but I will make a quick comment as this is still open.
I would say this is more like a design issue with the draw process. We can easily reproduce a similar behavior with two subplots where an annotation in the 1st subplot refers the the transAxes of the second subplot. I think we need to split the drawing process into two: first update the geometry of all the artists, and then draw. Or maybe three: update their extent, update location, and then draw. We may need some dependency tracking scheme with their geometry.
Maybe, we'd better create a new general issue for the discussion (and assemble all the related issues under it)?
I guess this works because the inset location is given in normalized axes coordinate, so its location is unchanged during its draw process. If you put 'axins.set_aspect(1.)', you will see that the location of the arrow becomes incorrect.
Yes, agreed - had the same problem w/ inset axes locators.
Lets start a new issue with as simple as possible a failing case and maybe we can work out a fix. But I think you are correct that the issue is the draw process sometimes needs to iterate, or at least be done twice before complicated layouts will work.
Calling apply_aspect (which calls the axes locator) seems to fix things.
A dangerous idea is for when the figure gets drawn call apply_aspect on all the children axes before the rest of the draw gets done. The danger is that apply_aspect is expensive, but I don't think its that expensive.
Activity
PiQuer commentedon Apr 23, 2015
Strangely enough, when commenting out the
savefig, what is shown interactively on screen is the wrong version, untilplt.draw()is called explicitely. After that, alsosavefigworks correctly, so this is a workaround.adrn commentedon Jul 29, 2015
@PiQuer are you saying that explicitly calling
draw()beforesavefig()is a workaround?I'm running in to this exact issue, I think, see my griping here.
adrn commentedon Jul 29, 2015
BTW different weirdness happens whether I save as PDF or PNG
WeatherGod commentedon Jul 29, 2015
attn: @mdboom. From the looks of it, it seems like the transform stack of
the annotated object (or the inset axes) is getting modified at each draw?
On Wed, Jul 29, 2015 at 8:29 AM, Adrian Price-Whelan <
notifications@github.com> wrote:
tacaswell commentedon Aug 1, 2015
I wonder if this is fixed by #4843
tacaswell commentedon Aug 1, 2015
no 😞 not fixed that branch.
tacaswell commentedon Aug 6, 2015
Maybe (?) related to #2831 (comment)
tacaswell commentedon Aug 6, 2015
@adrn That sort of griping is not the most effective at making devs want to help you. Without seeing your code I suspect you are using display-space units at some point which you should not be doing. Please open a new issue or send a note to the mailing list.
@PiQuer Does this work reliably on any version of mpl? Trying to sort out if this is a regression or a long standing bug.
I suspect this issues is related to the use of the inset axes which has some non-trivial logic in how it's transforms get managed. The inset axes has it's transforms defined in terms of the transforms of the parent axes. Currently the details of those transforms get set up (somehow, have not traced the code path yet) as part of the draw process off the inset axes. When it is initialized it's transforms have some default value. The annotation in the above code is a child of the inset axes. The way the draw tree is worked is that the parent axes, then all it's children, then the inset axes, then all of it's children are drawn. The source of the error here is that the annotation is drawn before the inset axes is drawn, and hence before it's transforms have been updated to reflect that it is an inset axes. The simplest work around is to just make the annotation belong to the inset axes so it is always drawn after the transfroms have been properly updated:
(the
clip_on=Falseis not really needed, but I don't understand why off the top of my head)Removing this from the next point release milestone because:
axes_grid, the draw process, or both.cc @leejjoon
PiQuer commentedon Aug 6, 2015
I will try to test in a couple of days, at the moment unfortunately I have no time to do it.
leejjoon commentedon Jul 23, 2018
I know this is rather old, but I will make a quick comment as this is still open.
I would say this is more like a design issue with the draw process. We can easily reproduce a similar behavior with two subplots where an annotation in the 1st subplot refers the the transAxes of the second subplot. I think we need to split the drawing process into two: first update the geometry of all the artists, and then draw. Or maybe three: update their extent, update location, and then draw. We may need some dependency tracking scheme with their geometry.
Maybe, we'd better create a new general issue for the discussion (and assemble all the related issues under it)?
jklymak commentedon Jul 23, 2018
FWIW:
Works fine on master.
example.pdf
leejjoon commentedon Jul 23, 2018
I guess this works because the inset location is given in normalized axes coordinate, so its location is unchanged during its draw process. If you put 'axins.set_aspect(1.)', you will see that the location of the arrow becomes incorrect.
jklymak commentedon Jul 23, 2018
Yes, agreed - had the same problem w/ inset axes locators.
Lets start a new issue with as simple as possible a failing case and maybe we can work out a fix. But I think you are correct that the issue is the draw process sometimes needs to iterate, or at least be done twice before complicated layouts will work.
Calling
apply_aspect(which calls the axes locator) seems to fix things.A dangerous idea is for when the figure gets drawn call
apply_aspecton all the children axes before the rest of the draw gets done. The danger is thatapply_aspectis expensive, but I don't think its that expensive.example.pdf
ImportanceOfBeingErnest commentedon Jul 12, 2019
Closing because this seems to be fixed by #11753. At least the pdf and screen output are now the same.