I am having difficulties exporting EPS figures. If I use the LineLegend option to create a dashed or a dot-dashed line, it seems ok in Mathematica 9.0 e.g.:

enter image description here

But the problem came out when the figure was expoted to EPS e.g., enter image description here

I use the following Mathematica code

G1 = ListPlot[{
      Table[{(i - 1) h, ρf[u, (i - 1) h, RKuOm, FB][[4, 4]]}, {i, 1, n - 1}],
      Table[{(i - 1) h, ρf[u, (i - 1) h, RKuOm, FB][[3, 3]]}, {i, 1, n - 1}], 
      Table[{(i - 1) h, ρf[u, (i - 1) h, RKuOm, FB][[2, 2]]}, {i, 1, n - 1}]
      PlotRange -> All, MaxPlotPoints -> Infinity, Joined -> True, 
      PlotLegends -> Placed[LineLegend[{Directive[Purple, Thickness[0.14]], 
       Directive[Blue, Thickness[0.14], Dashed], Directive[Red, Thickness[0.14], 
       DotDashed]}, {Style["\!\(\*SubscriptBox[\(ρ\), \(44\)]\)", 22, Bold], 
       Style["\!\(\*SubscriptBox[\(ρ\), \(33\)]\)", 22, Bold], 
       Style["\!\(\*SubscriptBox[\(ρ\), \(22\)]\)", 22, Bold]}, 
      LegendMarkerSize -> {{35, 8}}], {{0.82, 0.4}}], AspectRatio -> 0.8, 
      PlotStyle -> {{Purple, Thickness[0.012]}, {Blue, Thickness[0.014], 
       Dashed}, {Red, Thickness[0.013], DotDashed}},  Frame -> True, 
      FrameStyle -> Directive[Thick, 15],
      FrameLabel -> {Style["\!\(\*SubscriptBox[\(ω\), \(1\)]\)t", 18], None}, 
      Epilog -> {Inset[Style["(a)", 24, FontFamily -> "Times", Bold], {6, 0.95}], 
               Inset[Style["G=0.1", 24, FontFamily -> "Times", Bold], {41.5, 0.61}]}]


So, my question: why the style of the lines change? And how to solve?

Many thanks in advance.

  • 1
    $\begingroup$ Welcome to SE. Please post a minimal working example, ideally just containing some simple plot generation that exhibits the problem for you, so readers can reproduce. As it stands, your code is useless without the data/function definitions it needs. Please clarify where you see the problem, i.e., if you Import to Mathematica, is the problem there, or is it with some external viewer? $\endgroup$
    – ciao
    Mar 23, 2014 at 8:17
  • $\begingroup$ Try using Dashing or AbsoluteDashing and playing with the dash lengths. $\endgroup$
    – george2079
    Mar 23, 2014 at 16:18
  • $\begingroup$ With posted code I'm getting the expected error: Table::iterb : Iterator {i, 1, -1 + n} does not have appropriate bounds. What is n? $\endgroup$
    – murray
    Mar 23, 2014 at 21:31
  • $\begingroup$ @rasher Thank you, I am sorry for the error code. I think I could solve the problem by using AbsoluteDashing which is exactly the answer given by george2079. In addition, if the thickness of the lines are changed e.g.,Thickness[a] (a<0.01), I fond that I can use the posted code to export a normal EPS image, at least the dashed or the dotdashed lines would not turn into a straight line. $\endgroup$
    – Qu8k
    Mar 24, 2014 at 2:50
  • $\begingroup$ @george2079 Thank you for your help! AbsoluteDashing is very usefull. $\endgroup$
    – Qu8k
    Mar 24, 2014 at 2:56

1 Answer 1


Here is a more simple example showing the same effect:

 G1 = ListPlot[
      Table[{i , Sin[i j Pi/50]}, {j, 3}, {i, 50}], PlotRange -> All, 
      Joined -> True, AspectRatio -> 0.8, 
      PlotStyle -> {{Purple, Thickness[0.012]}, {Blue, Thickness[0.014], 
                    Dashed}, {Red, Thickness[0.013], DotDashed}}]
 Export["test1.eps", G1, "EPS"];

enter image description here

The problem turns out to be that postscript is putting linecaps on all the little segments that are proportional to the line thickness. If you look close you see the lines are "dashed" but the segments run together. (Screendump from Acrobat conversion of the eps)

enter image description here

The fix is to specify CapForm[] :

 G2 = ListPlot[
     Table[{i , Sin[i j Pi/50]}, {j, 3}, {i, 50}], PlotRange -> All, 
      Joined -> True, AspectRatio -> 0.8, 
      PlotStyle -> {{Purple, Thickness[0.012]}, {Blue, Thickness[0.014], 
        CapForm["Butt"], Dashed}, {Red, Thickness[0.013], DotDashed}}]
       Export["test3.eps", G2, "EPS"];

Oddly CapForm["None"] doesn't work.

Acrobat conversion of the eps:

enter image description here

Note the effect carried over to the second dashed line even though I only put it on the first.

Incedentally knowing this we can get (IMO) nicer dashing in eps with round linecaps and with explicit dashing specified:

  PlotStyle -> {{Purple, Thickness[0.012]}, {Blue, Thickness[0.014], 
       CapForm["Round"], Dashing[{0.014 2, 0.014 2}]}, {Red, 
         Thickness[0.013], Dashing[{1*^-10, 0.014 2, 0.014 2, 0.014 2}]}}

enter image description here

note the "really small" 10*^-10 dash length gives a perfect circle in the eps plot. ( 0 does not work as well ). Be aware the round caps are not supported by many (most?) export formats however.

  • $\begingroup$ +1. I really appreciate your answer! I thought that Mathematica's EPS export is desperate and (actually) unsupported but now I see that it is bad but not desperate! $\endgroup$ Mar 24, 2014 at 16:48
  • 1
    $\begingroup$ I've always liked it - it is the best vector graphics format in terms of publication quality (Except for lack of transparancy support), and other than a few quirks it is well supported by mathematica. This particular issue shows up because ps has this powerful linecap capability that no other vector format supports, so whoever wrote the Dashing defaults didn't take it into account. $\endgroup$
    – george2079
    Mar 24, 2014 at 17:56
  • $\begingroup$ This answer also applies to PDF exports, I have found. $\endgroup$
    – BBeast
    Aug 21, 2019 at 7:17

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.