-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Add URL support for images in PDF backend #23454
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
base: main
Are you sure you want to change the base?
Conversation
Case 2 solved. Remaining problems:
So for now I am pretty happy with it for now. |
f6e34a6
to
d401c1c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have not read the code yet.
The PDF backend can now generate clickable images if a URL is provided to the | ||
image. There are a few limitations worth noting though: | ||
|
||
* If parts of the image are clipped, the non-visible parts are still clickable. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this mean, if you zoom in on the image, parts outside the Axes will be clickable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. It is sort of easy to fix for non-transformed images (if there is a way to get the Axes extents from the gc(?). But for transformed it is much harder.
(I think the same holds for texts.)
* If there are transforms applied to the image, the whole enclosing rectangle | ||
is clickable. However, if you use ``interpolation='none'`` for the image, | ||
only the transformed image area is clickable (depending on viewer support). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I'm confused about what this means.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First sentence: Basically, the image with the hand drawn "rectangle" above is clickable. Probably there is a better wording for it.
Second sentence: if you rely on the PDF transform (i.e. set interpolation='none' and possibly a few more conditions) the clickable area is the image. Bracket part: not all PDF viewers support that and will fall back on the red rectangle.
OK, I know how to sort out the clickable outside of Axes-thing for non-transformed images (in theory for transformed as well, but will have to think a bit further regarding how many different cases there are and how to deal with them). |
PR Summary
Related to #23152
Currently, this doesn't work with a transform. If a standard transform is used, as in https://matplotlib.org/stable/gallery/images_contours_and_fields/affine_image.html it works, but the area is the "outline rectangle", rather than the exact area.
For transforms withHowever, for a plain image or a transformed withinterpolation='none'
it doesn't work at all.interpolation='none'
it works well.Note that one cannot use composite images (
plt.rcParams['image.composite_image']
must beFalse
) for this to work as the composite image doesn't have an URL set.There should be a release note outlining the limitations, but maybe I can figure out how to improve it slightly before that...
(This also includes a minor refactoring.)
PR Checklist
Tests and Styling
pytest
passes).flake8-docstrings
and runflake8 --docstring-convention=all
).Documentation
doc/users/next_whats_new/
(follow instructions in README.rst there).doc/api/next_api_changes/
(follow instructions in README.rst there).