How to export ContourPlot to vector graphics with fewer nodes?

Export["C:\\Users\\me\\Desktop\\example.pdf",
ContourPlot[(x^2 + y^2 - 1)^3 == x^2*y^3, {x, -5, 5}, {y, -5, 5},
PlotPoints -> 10, MaxRecursion -> 10, ContourStyle -> {Black},
Axes -> False, Frame -> False]]


Then I import example.pdf to Inkscape, there are more than 20k nodes,actually it's not a complex plot, I think 100 nodes are enough. How to control the nodes number when ContourPlot?

• Try disabling recursion and cranking up the setting for PlotPoints: ContourPlot[(x^2 + y^2 - 1)^3 == x^2*y^3, {x, -2, 2}, {y, -2, 2}, ContourStyle -> Black, Axes -> False, Frame -> False, MaxRecursion -> 0, PlotPoints -> 245] – J. M. is away Mar 4 '18 at 14:56
• @J.M.your method reduce the nodes but make this plot not smooth.And,the curve is very bold, I am not sure if any method to make the line thinner. – kittygirl Mar 4 '18 at 15:42
• For thickness, look up ContourStyle, Thickness and AbsoluteThickness. – Michael E2 Mar 4 '18 at 17:39
• I noticed you haven't accepted any answers to any of your questions. Perhaps we neglected to welcome you with our standard greeting: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour! 3) When you see good questions and answers, vote them up by clicking the gray triangles. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! – Michael E2 Mar 4 '18 at 20:38

ContourPlot does not make very efficient at making smooth graphs in general. In the present case, you can solve the equation for an explicit formula in polar coordinates:

polar = (x^2 + y^2 - 1)^3 == x^2*y^3 /. {x -> r Cos[t], y -> r Sin[t]} // Simplify;
foo = r /. First@Solve[polar, r, Reals];
PolarPlot[foo, {t, -Pi/2, 3 Pi/2}]
Cases[Normal@%, Line[p_] :> Length@p, Infinity] You can use the options to affect the number of points generated:

PlotPoints -> n,    (* default 50 *)
MaxRecursion -> r,  (* default 6 *)
Method -> {"Refinement" -> {"ControlValue" -> deg \[Degree]}} (* default 5 *)


The defaults produce 743 points. Much less than the OP's contour plot. IMO, hoping to get a smooth plot with ~100 points is very optimistic.

You might be able to do better splitting the polar plot in half, since that will resolve the cusps without excessive refinement:

Show[PolarPlot[foo, {t, -Pi/2, Pi/2}], PolarPlot[foo, {t, Pi/2, 3 Pi/2}]]


Here's a demo for exploring the option settings:

Manipulate[
With[{plot = Show[
PolarPlot[foo, {t, -Pi/2, Pi/2},
PlotPoints -> n, MaxRecursion -> r,
Mesh -> mesh, MeshStyle -> Red,
Method -> {"Refinement" -> {"ControlValue" ->
deg \[Degree]}},(*Exclusions\[Rule]None,*)
PerformanceGoal -> "Quality"],
PolarPlot[foo, {t, Pi/2, 3 Pi/2},
PlotPoints -> n, MaxRecursion -> r,
Mesh -> mesh, MeshStyle -> Red,
Method -> {"Refinement" -> {"ControlValue" ->
deg \[Degree]}},(*Exclusions\[Rule]None,*)
PerformanceGoal -> "Quality"]
]},
Graphics[
First@plot,
Frame -> True,
PlotRange -> Dynamic@pr[zoom],
PlotLabel ->
Row[{Total@Cases[Normal@plot, Line[p_] :> Length@p, Infinity],
" points"}],
AspectRatio -> 1
]
],
{{deg, 5}, 1, 50, Appearance -> "Labeled"},
{{n, 50}, 10, 200, 1, Appearance -> "Labeled"},
{{r, 6}, 0, 15, 1, Appearance -> "Labeled"},
{{zoom, 0}, -1, 1},
{mesh, {None, All}},
{{pr, Interpolation[{
{-1, {{-0.1, 0.1}, {-1.1, -0.9}}},
{0, {{-5, 5}, {-5, 5}}},
{1, {{-0.1, 0.1}, {0.9, 1.1}}}
}, InterpolationOrder -> 2]},
None}
] 200 points (above) do fairly well, except perhaps at the cusps. See the mesh button to All to see all the points.