6
$\begingroup$

I am plotting several functions, some of which have fillings. After I combine all the functions together on a plot and export the plot to an EPS file, the fillings obstruct other lines. Exported PDF files are fine.

Minimal Working Example:

Show[
  Plot[.5, {x, -1, 2}, PlotStyle -> {Thick, Dashed}],
  Plot[Sinh[x], {x, -1, 2}, Filling -> Axis]]

(I know I can write the two functions into a single Plot command, but I have to use Show to combine several separate plots in the real problem.)

Link to the exported EPS file

I can avoid the obstruction by saving the graphic as a bitmap, but the overall quality seems to be degraded.

$\endgroup$
8
$\begingroup$

Reverse your Plot calls in the Show function:

Show[Plot[Sinh[x], {x, -1, 2}, Filling -> Axis],
     Plot[.5, {x, -1, 2}, PlotStyle -> {Thick, Dashed}]]

Filling using transparency, and .eps doesn't support transparency, so upon export it sets the opacity equal to one. Since you are showing the line first, the filled plot is drawn on top of it and obscures the line upon export.

Edit: If you want to maintain the PlotRange set by the line plot, extract the PlotRange option by first plotting it by itself:

pl = Plot[.5, {x, -1, 2}, PlotStyle -> {Thick, Dashed}]
range = Options[pl, PlotRange];

And then use that to set the PlotRange option of the first plot:

Show[Plot[Sinh[x], {x, -1, 2}, Filling -> Axis, Evaluate@range], pl]

enter image description here

$\endgroup$
  • $\begingroup$ Thanks. That's helpful. Now I know why there couldn't be two fillings overlapping in EPS output. However in my work the combined picture needs the frame from the line plotting. And in the Show command it is always the first picture that makes the frame. I am trying to apply the same frame to the filling but without success. $\endgroup$ – TigTig Mar 5 '13 at 4:52
  • $\begingroup$ I edited my answer to address your comment. $\endgroup$ – Guillochon Mar 5 '13 at 5:26

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.