6
$\begingroup$

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?

$\endgroup$
4
  • 1
    $\begingroup$ Which Mathematica version do you use? I don't reproduce this problem with versions 12.3.1 and 13.0.0 on Windows 10 x64. $\endgroup$ Jan 26, 2022 at 6:54
  • $\begingroup$ working fine here too with MMA12.3.0 on Windows 10 x64. $\endgroup$ Jan 26, 2022 at 7:02
  • $\begingroup$ The issue is the same as in this question, but applying Normal doesn't help here (it drops the coloring information, what I consider as a bug). $\endgroup$ Jan 26, 2022 at 7:23
  • $\begingroup$ Thank you, I am using Mathematica 12.1.0.0 on Mac OS X 11.5 $\endgroup$
    – Andrea
    Jan 26, 2022 at 16:23

1 Answer 1

4
$\begingroup$

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"]

Mathematica graphics

Or this direct way:

ListPlot[
 MapThread[
  Style,
  {#, Function[{x}, Blend[{Red, Blue}, x]] /@ 
      Rescale[#[[All, 1]]]} &@{{1, 1}, {2, 2}, {3, 3}, {4, 4}}
  ]
 ]
$\endgroup$
2
  • 1
    $\begingroup$ Maybe I should add that it is the presence of VertexColors that triggers the rasterization, which happens when you specify a ColorFunction in *Plot* functions. $\endgroup$
    – Michael E2
    Jan 26, 2022 at 5:30
  • 1
    $\begingroup$ (+1) Actually, Normal should do the conversion. But currently, it simply drops the VertexColors what I consider as a bug. $\endgroup$ Jan 26, 2022 at 6:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.