If I save the figure generated by ListPlot[{{1, 1}, {2, 2}, {3, 3}, {4, 4}}]
as a PDF and open it in Affinity Designer (an alternative to Adobe Illustrator), the figure is vectorial and I can modify individual points, axes, etc. However, if I save the figure generated by ListPlot[{{1, 1}, {2, 2}, {3, 3}, {4, 4}}, ColorFunction -> Function[{x}, Blend[{Red, Blue}, x]]]
, I get a rasterized image whose elements cannot be modified. Is there a way to get a vectorized image while specifying a ColorFunction
?
1 Answer
It can't be done easily with lines and polygons (because you'd have to construct gradients but subdividing the objects), but it could be done with points, as in your example. Are you only interested in ListPlot
of points?
vcRules[vc_] := {
HoldPattern[Point[p_List, VertexColors -> Automatic]] :>
({RGBColor @@ vc[[#]], Point[#]} & /@ p),
HoldPattern[Point[p_List, VertexColors -> c_List]] :>
Riffle[c, Point[#] & /@ p]
};
ListPlot[{{1, 1}, {2, 2}, {3, 3}, {4, 4}},
ColorFunction -> Function[{x}, Blend[{Red, Blue}, x]]] /.
GraphicsComplex[p_, g_, o1___, HoldPattern[VertexColors -> vc_], o2___] :>
GraphicsComplex[p, g /. vcRules[vc], o1, o2]
Export["/tmp/test.pdf", %];
Import[%, "PageGraphics"]
Or this direct way:
ListPlot[
MapThread[
Style,
{#, Function[{x}, Blend[{Red, Blue}, x]] /@
Rescale[#[[All, 1]]]} &@{{1, 1}, {2, 2}, {3, 3}, {4, 4}}
]
]
-
1$\begingroup$ Maybe I should add that it is the presence of
VertexColors
that triggers the rasterization, which happens when you specify aColorFunction
in*Plot*
functions. $\endgroup$ Jan 26, 2022 at 5:30 -
1$\begingroup$ (+1) Actually,
Normal
should do the conversion. But currently, it simply drops theVertexColors
what I consider as a bug. $\endgroup$ Jan 26, 2022 at 6:59
Normal
doesn't help here (it drops the coloring information, what I consider as a bug). $\endgroup$