Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
Loading
from

Conversation

oscargus
Copy link
Member

@oscargus oscargus commented Jul 20, 2022

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 with interpolation='none' it doesn't work at all. However, for a plain image or a transformed with interpolation='none' it works well.

Note that one cannot use composite images (plt.rcParams['image.composite_image'] must be False) 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

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (install flake8-docstrings and run flake8 --docstring-convention=all).

Documentation

  • New features are documented, with examples if plot related.
  • New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).

@oscargus
Copy link
Member Author

Basically, there are two things that can/should be fixed.

  1. When performing a transform, I would like to know the corners of the actual image contents, not the "outline rectangle", the red part in
    image

However, it seems like all one has access to at this stage is the NumPy array, where the values are already transformed?

When performing a transform using the PDF transform mechanism (typically triggered when `interpolation='none'), I need something similar that determined the corners of the actual image based on the six values of the PDF transformation.

For the latter case it is just a matter of sorting out the trigonometry.

@oscargus
Copy link
Member Author

oscargus commented Jul 21, 2022

Case 2 solved.

Remaining problems:

  • Case 1 above (I think one way is to try to detect where alpha = 0 and based on that try to detect the actual corners, but I do not think it that I will be able to do that in the near future
  • Images that are clipped will be clickable even on the clipped parts. This is not trivial to fix as one need "QuadPoints", i.e. skewed and rotated rectangles, so in many cases this will end up with multiple QuadPoints.

So for now I am pretty happy with it for now.

@oscargus oscargus force-pushed the pdfimageurl branch 4 times, most recently from f6e34a6 to d401c1c Compare July 21, 2022 12:44
@oscargus oscargus marked this pull request as ready for review July 21, 2022 12:44
Copy link
Member

@QuLogic QuLogic left a 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.
Copy link
Member

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?

Copy link
Member Author

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.)

Comment on lines +8 to +10
* 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).
Copy link
Member

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.

Copy link
Member Author

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.

@oscargus oscargus marked this pull request as draft July 23, 2022 14:24
@oscargus
Copy link
Member Author

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).

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

Successfully merging this pull request may close these issues.

2 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.