Rasterized colorbars in PDFs are not recognized by Adobe Illustrator
See original GitHub issueWhen 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:
from plotnine import *
import numpy as np
x = np.linspace(0, 1, 10)
g = qplot(x, x, color=x, geom='point')
ggsave(g, 'ggplot-python.pdf')
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:
f, ax = plt.subplots(figsize=(4,0.5))
gradient = np.linspace(0, 1, 256)
gradient = np.vstack((gradient, gradient))
ax.imshow(gradient, aspect='auto', cmap=plt.get_cmap('viridis'))
f.savefig('matplotlib.pdf')
Last, I tried the R equivalent of the first code:
library(ggplot2)
x = seq(0, 1, by=0.1)
g = qplot(x, x, color=x)
ggsave('ggplot-R.pdf')
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.
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (7 by maintainers)
Top GitHub Comments
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.
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!