3
$\begingroup$

I have a function defined on a 3D surface, which I wish to plot as a contour plot, and export to a vector graphics format. Based on this question and various others, it seems that there is generically no way to do this for 3D plots (unless something has been introduced since v10). I tried RegionPlot and ParametricPlot3D with MeshFunctions, etc, but they all export raster graphics.

However, is there some hack to make it work for a function where I only wish to export the contour lines themselves (i.e. no shading or gradients) on the surface of a sphere? In 2D, it's possible to nicely simplify the plotted lines as in the solutions to this question, so can something like this somehow be generalised to lines on the surface of a sphere? Or is it strictly only 2D graphics that are supported for vector output?


Edit

A (simplified) example of the sort of plot I mean:

ParametricPlot3D[{Sin[\[Theta]] Sin[\[Phi]], 
  Cos[\[Phi]] Sin[\[Theta]], Cos[\[Theta]]}, {\[Theta], 
  0, \[Pi]}, {\[Phi], 0, 2 \[Pi]}, 
 MeshFunctions -> {{x, y, z, \[Theta], \[Phi], r} |-> 
    Sin[2 \[Theta]] Cos[\[Phi]]}, PlotStyle -> Opacity[0], 
 MeshStyle -> Thickness[Medium]]

contour lines on a sphere

$\endgroup$
3
  • $\begingroup$ Contour surfaces or contour lines? An example showing something to be exported would help. $\endgroup$
    – Michael E2
    Commented Nov 7, 2022 at 12:18
  • $\begingroup$ just the contour lines, over a simple 3D surface $\endgroup$
    – user366202
    Commented Nov 7, 2022 at 12:29
  • $\begingroup$ Yes, now we can only use Mathematica 9.0 to export 2D vector format pdf file. $\endgroup$
    – cvgmt
    Commented Nov 7, 2022 at 12:37

2 Answers 2

6
$\begingroup$

Or project to 2D plane and export to 2D vector format pdf.

plot = ParametricPlot3D[{Sin[θ] Sin[ϕ], 
    Cos[ϕ] Sin[θ], Cos[θ]}, {θ, 
    0, π}, {ϕ, 0, 2 π}, 
   MeshFunctions -> 
    Function[{x, y, z, θ, ϕ, r}, 
     Sin[2 θ] Cos[ϕ]], PlotStyle -> Opacity[0], 
   MeshStyle -> Thickness[Medium], PlotPoints -> 80, 
   MaxRecursion -> 4, Axes -> False, ViewProjection -> "Orthographic",
    ViewPoint -> {1, 1, 1}, Boxed -> False];
twodimplot = 
  Graphics[
   plot[[1]] /. {x_Real, y_Real, z_Real} -> 
     Most[RotationMatrix[{{0, 0, 1}, {1, 1, 1}}] . {x, y, z}]];
Export["test.pdf", twodimplot]
SystemOpen["test.pdf"]

enter image description here

$\endgroup$
3
$\begingroup$

Is a Tube okay?

foo = ParametricPlot3D[{Sin[\[Theta]] Sin[\[Phi]], 
   Cos[\[Phi]] Sin[\[Theta]], Cos[\[Theta]]}, {\[Theta], 
   0, \[Pi]}, {\[Phi], 0, 2 \[Pi]}, 
  MeshFunctions -> {{x, y, z, \[Theta], \[Phi], r} |-> 
     Sin[2 \[Theta]] Cos[\[Phi]]}, PlotStyle -> Opacity[0], 
  MeshStyle -> Tube[0.02]]
Export["/tmp/foo.svg", foo]

enter image description here

$\endgroup$

Your Answer

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

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