Closed gokceneraslan closed 2 years ago
Apparently this is about the rasterization of the colorbar. But I'm still confused.
ggplot(aes(x='x', y='x', color='x'), data=df) + geom_point() + guides(color=guide_colorbar(raster=False, nbin=100))
This plot looks fine and the colorbar is editable, it's bunch of rectangles after all. However I still do not understand why rasterized colorbar is not recognized by Illustrator. Interestingly, R also rasterizes the colorbar by default but it looks totally fine in Illustrator.
@has2k1 Could this be about the shading in QuadMesh? I'm sure you looked into it before.
import matplotlib.pyplot as plt;
import numpy as np;
x1 = np.random.randn(100);
x2 = np.random.randn(100);
x3 = np.random.randn(100, 100);
fig, ax = plt.subplots();
quadMeshCol = ax.pcolormesh(x1, x2, x3, shading='gouraud');
plt.show();
gives the same error whereas
import matplotlib.pyplot as plt;
import numpy as np;
x1 = np.random.randn(100);
x2 = np.random.randn(100);
x3 = np.random.randn(100, 100);
fig, ax = plt.subplots();
quadMeshCol = ax.pcolormesh(x1, x2, x3, shading='flat');
plt.show();
is perfectly fine, therefore it seems like shading is the problem.
I was wondering if we can simply pass rasterized=True
to the PolyCollection
, so I made the following modification:
But then the colorbar is misplaced in the plot:
I also wonder if there are things to borrow from mpl's colorbar, which renders fine, is editable and not rasterized at all.
Thanks for trying to get to the bottom of this. This issue is like bad xml/html markup where some tag/attribute is badly encapsulated. I think I will wait and see want comes from the matplotlib bug report.
Thanks @has2k1 . Do you remember why you do not simply rasterize the PolyCollection and use QuadMesh without rasterized=True
(so actually without any rasterization) instead?
I recall to have looked at how the colorbar was implemented in Matplotlib, it was quite involved but I noticed that Quadmesh
was used and so I built a solution using Quadmesh. I do not recall even thinking about PolyCollection!
When I try to edit a PDF generated by plotnine in Illustrator, I get an
An unknown imaging construct was encountered.
warning if there is a continuous color scale in the plot (e.g. gradient). This also makes the color legend uneditable. I was wondering why this might be happening and so I made some experiments with matplotlib and also ggplot2 in R.This is a simple example to generate such a plot:
Here is how it looks like in Illustrator, big X sign indicates the "unknown imaging construct" (for some reason it covers the entire image but it is actually only due to the color legend):
When I move the legend around:
However a simple gradient produced directly by matplotlib renders fine and is editable:
Last, I tried the R equivalent of the first code:
Color bar in this PDF looks perfectly fine and there is no warning at all:
I know that asking for a fix that affects only (and is reproducible only with) Illustrator which is a proprietary software, is not very meaningful, given that plotnine is a great free software. But I just wanted to ask if there is anything weird about the PDFs with gradients produced by plotnine, or can we make them more "R-like" so that they are easier to edit.
Cheers.