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
multiple imshow in figure are rendered as single image in svg, causing problems when clipping images #7151
I am on matplotlib 1.5.1 (but i suppose this is not related with this specific version)
This is probably a bug/limit of the svg export engine (maybe known?)
when multiple calls to imshow are made in the same figure and then saved in svg ALL the calls are joined into a single raster instead of having multiple (e.g. grouped) images in the svg file.
This make fail a simple test case like this. We call two times imshow to position two images in the figure, then we clip the two images with two different shapes. The problem is that in the svg the two imshow calls are joined in an unique raster, thus the clips are simply not created at all in the svg. Exporting each imshow() raster as a separated image in the svg, each with their clips, would probably solve the problem.
Is it possible or is a known limit?
if saved as png:
and as svg:
Code for generating these pictures (for a notebook):
changed the title [-]multiple imshow in image are rendered as single image in svg, causing problems when clipping images[/-][+]multiple imshow in figure are rendered as single image in svg, causing problems when clipping images[/+]on Sep 21, 2016
By default, we composite images for output to vector graphics formats. I
think if you set the rcParam "image.composite_image" to False, you'll get
what you want.
I am on matplotlib 1.5.1 (but i suppose this is not related with this
specific version)
This is probably a bug/limit of the svg export engine (maybe known?)
when multiple calls to imshow are made in the same figure and then saved
in svg ALL the calls are joined into a single raster instead of having
multiple (e.g. grouped) images in the svg file.
This make fail a simple test case like this. We call two times imshow to
position two images in the figure, then we clip the two images with two
different shapes. The problem is that in the svg the two imshow calls are
joined in an unique raster, thus the clips are simply not created at all in
the svg. Exporting each imshow() raster as a separated image in the svg,
each with their clips, would probably solve the problem.
Is it possible or is a known limit?
probably should detect if the artist have non-trivial clipping and if so, opt them out of the optimization.
The only place the compositing really helps you if you have many overlapping images, in the OPs case it might have been hurting (independent of the clipping bug!).
https://github.com/matplotlib/matplotlib/blame/v0.91.2/lib/matplotlib/axes.py
If you use git blame and look for "composite" you will see that this logic in the draw method is old. It might have been put in because postscript doesn't handle alpha, so if we wanted composited images with alpha, we had to do it ourselves. This is still true, of course. At the time, it would also have been true for some other backends that we no longer support.
In my opinion, given changing default behaviours is always risky, better documenting this might be a good starting point. My problem wasn't actually the behaviour of the svg compositing engine, but that I was not able to find the right switch to turn for solving the problem. Even if you google "image.composite_image" you see how much is difficult to get what it does. #2517 btw is the same.
An example in the cookbook or similar with the right keywords, pointing to this and other issues, will definitively help. Or even add better info into the doc (?)
Maybe the info are there but I had difficult times finding them...
said that a default option which creates discrepancies between format outputs maybe should be investigated better
Activity
[-]multiple imshow in image are rendered as single image in svg, causing problems when clipping images[/-][+]multiple imshow in figure are rendered as single image in svg, causing problems when clipping images[/+]WeatherGod commentedon Sep 21, 2016
By default, we composite images for output to vector graphics formats. I
think if you set the rcParam "image.composite_image" to False, you'll get
what you want.
On Wed, Sep 21, 2016 at 5:39 AM, Luca notifications@github.com wrote:
luca-penasa commentedon Sep 21, 2016
cool!
This totally solves the problem!
Thank you a lot, maybe it should be the default behaviour given it causes a different output for svg and png?
Many thanks and feel free to close the ticket!
QuLogic commentedon Sep 21, 2016
Is this really not a bug? Compositing is an optimization, but it shouldn't break things in alternate formats.
Kojoley commentedon Sep 21, 2016
I was wondering about this too.
And this is true not only for svg (tested pdf and it is affected).
tacaswell commentedon Sep 21, 2016
probably should detect if the artist have non-trivial clipping and if so, opt them out of the optimization.
The only place the compositing really helps you if you have many overlapping images, in the OPs case it might have been hurting (independent of the clipping bug!).
tacaswell commentedon Sep 21, 2016
Which is a long way of saying, flipping this to off by default might be a reasonable thing to do
@mdboom @efiring do you know the history of this?
QuLogic commentedon Sep 21, 2016
Also of note is that there was a significant image infrastructure rewrite, so we should check what happens with 2.x and/or master.
efiring commentedon Sep 21, 2016
I think it goes way back, but I don't remember whether it was put in by JDH or by Mike.
efiring commentedon Sep 21, 2016
https://github.com/matplotlib/matplotlib/blame/v0.91.2/lib/matplotlib/axes.py
If you use git blame and look for "composite" you will see that this logic in the draw method is old. It might have been put in because postscript doesn't handle alpha, so if we wanted composited images with alpha, we had to do it ourselves. This is still true, of course. At the time, it would also have been true for some other backends that we no longer support.
luca-penasa commentedon Sep 22, 2016
In my opinion, given changing default behaviours is always risky, better documenting this might be a good starting point. My problem wasn't actually the behaviour of the svg compositing engine, but that I was not able to find the right switch to turn for solving the problem. Even if you google "image.composite_image" you see how much is difficult to get what it does. #2517 btw is the same.
An example in the cookbook or similar with the right keywords, pointing to this and other issues, will definitively help. Or even add better info into the doc (?)
Maybe the info are there but I had difficult times finding them...
said that a default option which creates discrepancies between format outputs maybe should be investigated better
Thanks again everybody for this great library 👍
Luca
Turn off image compositing to allow separating layers in vector graph…
QuLogic commentedon Mar 9, 2023
This was fixed by #19375 in 3.5.0.