-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Adding colorbars to row subplots doesn't render the main plots when saving to .eps in 1.5.0 #5814
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 can reproduce with 1.5.1rc1 By opening the file in inkscape I can see that the issue is the bbox of the colorbar. It extends well beyond the colorbar it self and is plotted on top of the image to the right. |
I think this is a bug in the rasterising code revealed by #4481 If I disable the rasterization it looks right: import matplotlib.pyplot as plt
import numpy as np
data = np.random.rand(100,100)
fig, ax = plt.subplots(1,2)
p1 = ax[0].pcolormesh(data)
p2 = ax[1].pcolormesh(data)
cb = plt.colorbar(p1,ax=ax[0])
plt.colorbar(p2,ax=ax[1])
cb.solids.set_rasterized(False)
fig.tight_layout()
fig.canvas
fig.savefig('test.pdf')
fig.savefig('test.eps') |
This comes from the fact that the Postscript file format doesn't support alpha blending. So when you have an image with transparent pixels, they come out as white. I suppose the best thing to do here is to turn off the colorbar rasterization when using the Postscript backend... I'll try to work up a PR shortly. |
but, why is the bounding box for the colorbar not constrained? On Fri, Jan 8, 2016 at 12:25 PM, Michael Droettboom <
|
This is going to be tricky to fix. The code that turns on rasterizing of colorbars is ignorant of the backend in use (and probably should remain so). The Postscript backend should probably be fixed so that when the rasterized layer contains alpha it falls back to not rasterizing. But I don't think it can figure that out before it actually rasterizes, so then it would have to store and play back the backend calls... I'd really like to deprecate the Postscript backend -- there are fewer and fewer cases where Postscript is required but PDF can't be used instead. But I know there still a few tools and workflows that need Postscript, so that's probably not realistic yet. |
I think the code that "minimizes" the image is somehow broken... |
How about we focus on fixing that first to minimize the impact this bug has? On Fri, Jan 8, 2016 at 12:35 PM, Michael Droettboom <
|
I winder if this problem exists also for pcolormesh plots, or if it is On Fri, Jan 8, 2016 at 12:41 PM, Benjamin Root ben.v.root@gmail.com wrote:
|
It's for anything that's rasterized (in this particular case, just the colorbars). I have a fix that I'll post shortly. |
The creation of the bounding box of actual image content is wrong.
I upgraded to matplotlib 1.5.0 and ran into a potential bug involving colorbars, subplots and saving to .eps for which the only workaround I found was to downgrade back to 1.4.3 where the problem doesn't exist.
Essentially, the .eps output gets corrupted when multiple subplots in a row array (e.g. 1x2) have colorbars added to them. This results in a blank canvas on the main plots of all heatmaps but the first one in the .eps output, whereas the .pdf output works as intended.
A minimal working example:
These are the outputs (converted to .png, the top line in the .eps output in the second subplot is just an artefact from converting to .png):
.pdf:

.eps:

The problem persists when replacing pcolormesh with pcolor or imshow, using cax for colorbar axis instead of ax, changing colormaps, using row arrays of more subplots (for 1xn the last n-1 subplots have empty canvas), using gridspec to define subplots. The only thing that resolved this was to downgrade back to 1.4.3.
The text was updated successfully, but these errors were encountered: