1
$\begingroup$

I am trying to make a relatively complex 3D plot in order to show the variation of a curve with a parameter. Here is the code

AnsNf[x_, nf_] = (2 \[Pi] x^4)/((11 - (2 (2 + nf))/3) (1 + 1/2 x^6 Log[4. x^2])) + (14.298 (1 + (1.81 - 0.292 nf) x^2 - 2.276 x^2 Log[x^2/(1 + x^2)]))/(1 + (9.926 + 1.795 nf) x^2 + (1.1 - 4.964 nf) x^4 + (22.412 +5.612 nf) x^6); 
AnsNfnoc[x_, nf_] = (2 \[Pi] x^4)/((11 - (2 (2 + nf))/3) (1 + 1/2 x^6 Log[4. x^2])) + (14.298 (1 + (1.81` - 0.292 nf) x^2 - 0.569 x^2 Log[x^2/(1 + x^2)]))/(1 + (9.926 + 1.795 nf) x^2 + (1.1 - 4.964 nf) x^4 + (22.412 +5.612 nf) x^6);

AnsatzINf[t_, i_] := t^2*AnsNf[t, i - 1];
AnsatzINfNoc[t_, i_] := t^2*AnsNfnoc[t, i - 1];

colsandthick = {{RGBColor[175/255, 0, 28/255], Thickness[0.004]}, {RGBColor[14/255, 95/255, 177/255], Thickness[0.004]}, {RGBColor[130/255, 120/255, 106/255], Thickness[0.004]}, {RGBColor[0/255, 102/255, 128/255],Thickness[0.004]}};
colsandthickanddot = {{RGBColor[175/255, 0, 28/255], Thickness[0.004],CapForm["Round"],Dashing[{1*^-10, 0.01}]}, {RGBColor[14/255, 95/255, 177/255],Thickness[0.004], CapForm["Round"],Dashing[{1*^-10, 0.01}]}, {RGBColor[130/255, 120/255, 106/255],Thickness[0.004], CapForm["Round"],Dashing[{1*^-10, 0.01}]}, {RGBColor[0/255, 102/255, 128/255],Thickness[0.004], CapForm["Round"], Dashing[{1*^-10, 0.01}]}};
p1 = Graphics3D[Table[{Plot[{AnsatzINf[t, i], AnsatzINfNoc[t, i]}, {t, 0, 5},PlotStyle -> {colsandthick[[i]], colsandthickanddot[[i]]}][[
  1]]} /. {x_?NumericQ, y_?NumericQ} :> {x, i, y}, {i, 1, 4}], Axes -> {True, True, True}, Boxed -> {Left, Bottom, Back},BoxRatios -> {1, 1, 0.5},FaceGrids -> {{0, 0, -1}, {0, 1, 0}, {-1, 0, 0}},AxesStyle ->Directive[FontFamily -> "Helvetica", FontSize -> 16,Thickness[0.003], Black],FaceGridsStyle ->Directive[GrayLevel[0.3, 1], AbsoluteDashing[{1, 2}]], ViewPoint -> {2.477268549689875`, -2.189130098344112`,0.566436179318843`}, ViewVertical -> {0, 0, 1},ImageSize -> Large]

This code produces the following plotenter image description here which is already weird because each continuous curve should be accompanied by a lower line (specified by the function "AnsNfnoc") that should be rendered through a dotted line as specified by the "colsandthickanddot" styling option.

While I could live with this (but why is this so?), the real problem comes when I export the plot in pdf: as shown below, the dotted curves are now rendered, but the dashing is unevenly spaced. enter image description here

I am under the impression that this is due to some mesh applied when rendering the 3D plot, but do you have any idea how this could be corrected in such a way that the space between the dots is rendered evenly?

$\endgroup$
  • $\begingroup$ You have two separate issues. First, why is your dashed line not showing up in the 3D plot in your notebook, that's an easy question to answer. Second, why doesn't the exported PDF show the dashing? To look at that, we need more info, operating system, version number, etc. Try a simpler example, Export["test.pdf", ParametricPlot3D[{t, 4, AnsatzINf[t, 4]}, {t, 0, 4}, PlotStyle -> colsandthickanddot[[4]]] ] and see if that shows the dashing in the plot. $\endgroup$ – Jason B. Nov 3 '16 at 14:04
  • $\begingroup$ The reason the dashed line doesn't show up in the 3D plot in your notebook is that you are using an aggressive replacement rule. It takes the pair of numbers inside your Dashing command and replaces them with 3 numbers. To confine the replacement rule to the lines only, try using /. Line[a_] :> Line[{#1, i, #2} & @@@ a] instead. Or, better yet, use ParametricPlot3D and you won't need to do any replacemnts. $\endgroup$ – Jason B. Nov 3 '16 at 14:06
  • $\begingroup$ Thank you @JasonB for the tip about the "ParametricPlot3D" version of my plot. I have tried to use it and indeed the dashing is rendered now in the Mathematica output. However again the dashing is poorly rendered in the pdf export (just to be precise: dashing has been always shown up in the pdf export; the problem is the uneven space between the dots). This is the pdf export I got which shows the problem. I am on a Mac, running Mac OS Sierra and Mathematica 10.0.1.0 $\endgroup$ – Daniele Binosi Nov 3 '16 at 14:56
  • $\begingroup$ To elaborate a bit about my guess that it is a mesh related issue, at this link you'll find a pdf export of the same plot in which I have filled the upper and lower curves. If you look carefully you will see bunches of white mesh lines originating from the upper curves end ending on the location of the dots in the lower curve (even though admittedly this might be an effect rather than a cause). $\endgroup$ – Daniele Binosi Nov 3 '16 at 15:48
  • $\begingroup$ Possible duplicates: (5895), (79278) $\endgroup$ – Michael E2 Nov 4 '16 at 1:23
1
$\begingroup$

Just add the Dashed directive before the Plot:

[...] Table[{Dashed, Plot[{AnsatzINf[t, [...]

Knowing that, you can divide your Plot and only add the Dashed directive before the curves you want.

enter image description here

$\endgroup$
  • $\begingroup$ Hi DPF, thank you for your suggestion. While this will render the curve in Mathematica (to the expense, as far as I can tell, of a certain loss of freedom in defining the dashing pattern) it will not solve the export to PDF problem which will still show an unevenly dashing. $\endgroup$ – Daniele Binosi Nov 3 '16 at 13:05
0
$\begingroup$

Try ParametricPlot3D instead.

img = ParametricPlot3D[
  Evaluate@
   Flatten[Function[{i}, {t, i, #} & /@ 
      {AnsatzINf[t, i], AnsatzINfNoc[t, i]}] /@ Range[4], 1],
  {t, 0, 5},
  PlotStyle -> Riffle[colsandthick, colsandthickanddot],
  Boxed -> {Left, Bottom, Back},
  ImageSize -> Large]

Mathematica graphics

Just add the remaining options.

If "PDF" still will not cooperate then Rasterize before export.

Export["test.pdf", Rasterize[img, "Image", ImageResolution -> 300], "PDF"]

Hope this helps.

$\endgroup$
  • $\begingroup$ Uh, but making it a rasterimage renders the entire PDF process useless, does it not? The interesting part of having a direct PDF export would be having it as vector data, right? $\endgroup$ – mikuszefski Nov 4 '16 at 8:46
  • $\begingroup$ Thank you, but rasterising is not an option in my case. $\endgroup$ – Daniele Binosi Nov 4 '16 at 9:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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