Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Wrong coordinate transform on jupyter notebook (inline backend) #4865

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
gabrielelanaro opened this issue Aug 4, 2015 · 5 comments
Closed
Milestone

Comments

@gabrielelanaro
Copy link

Hi, I've been trying to the example http://matplotlib.org/pyplots/annotate_transform.py in jupyter notebook (inline backend) as described in the transformation tutorial http://matplotlib.org/users/transforms_tutorial.html

However the picture I obtain is somehow shifted from the expected output:
download

Is this something you can reproduce? How can I fix that?
I'm using the matplotlib version just pulled from git

@tacaswell
Copy link
Member

maybe related to #4375 ?

@tacaswell tacaswell added this to the next point release milestone Aug 5, 2015
@gabrielelanaro
Copy link
Author

I think this is definitely related even though I wasn't able to have it working in any way

@tacaswell
Copy link
Member

The documentation does warn in the note that it might not work correctly in the interactive cases.

The reason is that the transformation from data space -> screen space depends on the dpi and figure size. In this case the pixel location of the point is being computed. IPython turns the dpi on the figures produced by inline way down, hence why you get the shift.

I think the behavior you are seeing is the correct and expected behavior. You should do your best to avoid working in screen units.

@gabrielelanaro
Copy link
Author

What I'm trying to do is connect points between two inset axes (similarly to #4375). I was wondering, if I run savefig (from terminal), isn't that supposed to work properly? I still get a different offset. I think that's likely because png renderer does as well scale the picture, but how do we know what dpi setting I should set so that the pre-render screen coordinate and post-render screen coordinates match?

hello

@tacaswell
Copy link
Member

The problem is still that you are computing the pixel to point to with one set of transforms and rendering the final figure (most likely either the figure size or dpi changed). Unless you are super careful and/or re-compute the pixel location on every draw stay I strongly advise against using absolute pixels for anything.

As with #4375 the transforms on inset axes may not be initialized until after the first draw. Attach the annotation to the inset axes with the highest zorder.

It would be helpful if you posted a minimal example demonstrating your problem.

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

No branches or pull requests

2 participants