-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
PGF Backend: Support interpolation='none'? #6740
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
Comments
I found that in the case of a simple scaling, This implementation does not support any other transformation than Side note: The original backend received a pre-scaled image of 577 x 481 pixels, my modified backend (with |
I could, but then the backend cannot cope with arbitrary affine image transforms any longer. I guess this is not what we want. Let's spell out the options (sorry for the wall of text above):
Option E could be realized as an extension of |
Option C would probably be solvable with |
Oh, and another thing: I based my modified backend on matplotlib 1.5.2, which has Maybe Option C would be the best solution then. Option E would require peeling out the scaling factors from the transform, which wouldn't be too hard either if we know it's a scale transform. |
I don't remember the exact details when I implemented the function back then, but I vaguely remember some thoughts concerning image transformation within PGF.. unfortunately I didn't document them. First of all, the lack of documentation on how I agree that the best solution is to move all transformations to the PGF layer. Thanks for the But I'd also like to ask the question "is it really worth it?". We do have perfect matching with other backends, and I don't believe that 10x or 100x upscaled images grow considerably in size after being PNG compressed. Can't be more than a few kB, right? Also remember that there is |
It's difficult to hit an exact integer upscaling factor, though -- I can influence it via the dpi setting, but if it was easy to hit a certain factor, I could also just set the dpi so it hits a factor of 1. So most of the time, Now I agree that for a 5x6 pixels image, the gain is negligible. I can blow it up to about 500x600 and rest assured that nobody will notice whether some of the 100x100 pixels are actually 99x99 or 101x101, without wasting too much space. However, this was just a showcase, I'm actually plotting spectrogram excerpts. When they're blown up by a factor of 10 or 100, they get unmanageably large. When I don't blow them up, they get awkwardly distorted in the process of plotting. When I set
Good to know! (Not for this case, but in general.)
Is this tested anywhere? |
I'm currently trying to figure out the best way to unify the figures for my thesis, and intend to use the PGF backend to directly
\include
figures in my LaTeX document.When creating PGF figures that include raster graphics (e.g., via
imshow
), the graphic gets stored as a PNG file and imported via\pgfimage
, which is great. Unfortunately, it doesn't supportinterpolation='none'
as the PDF backend does:Checking the created PDF file in Evince, it indeed includes a PNG graphic of 5x6 pixels. The graphic for the PGF file is blown up, though:
I can manually fix this by replacing it with a 5x6 PNG file and tweaking the PGF output as follows:
Can we modify the PGF backend such that it emits the unscaled raster graphic and uses
interpolate=false
?I'm willing to work on this myself, but would appreciate some guidance. Looking through the code, the image is written in https://github.com/matplotlib/matplotlib/blob/f1bab50/lib/matplotlib/backends/backend_pgf.py#L612.
The corresponding code in the PDF backend starts at https://github.com/matplotlib/matplotlib/blob/f1bab50/lib/matplotlib/backends/backend_pdf.py#L1600.
It overrides the
option_scale_image()
function to returnTrue
, and it takes an additionaltransform
parameter indraw_image()
. I guess this is where the magic happens -- if there's a transformation to apply, it will get the unmodified image and construct the PDF so the image is scaled appropriately.The documentation on that parameter is scarce (https://github.com/matplotlib/matplotlib/blob/f1bab50/lib/matplotlib/backend_bases.py#L511), but it seems you can convert it into six values giving an affine transformation.
If I want the PGF backend to handle scaling, will the backend have to handle the full range of possible affine transformations (scaling would suffice for me)? Is the
transform
guaranteed to only be used forinterpolation='none'
, so I can setinterpolate=false
in this case? Is there any better documentation on thetransform
?The text was updated successfully, but these errors were encountered: