6
$\begingroup$

I'm new to Mathematica so I apologize if this is obvious to answer. Anyway, using the following code (most of it is extraneous, to make the plot look the way I want) I plotted the Morse potential,

V[r_] := Exp[-2 (r - 1)] - 2 Exp[-(r - 1)]
p = Plot[V[r], {r, 0, 5}, Ticks -> {Range[0, 5, .5], Range[-1, 1, .25]}, 
  TicksStyle -> Directive[FontOpacity -> 0, FontSize -> 0], 
  AxesLabel -> {HoldForm[r], HoldForm[V[r]]}, 
  AxesStyle -> Arrowheads[0.035]]

which yields

enter image description here

Now when I export this as PDF, using

Export["PathToLocation\\morse-potential.pdf", p, "PDF"]

the $V(r)$ label gets scrambled a bit:

enter image description here

I've also tried what would happen if I left out the optional arguments: the ticks are rendered exactly the same way,

enter image description here

What's going on here and how can I avoid it? I'm on Win8 with Mathematica 10.0.1.0 and Adobe Reader 11.0.10.

$\endgroup$
  • 1
    $\begingroup$ what OS? versions? $\endgroup$ – Nasser Apr 2 '15 at 11:51
  • $\begingroup$ I'm on Win8 with Mathematica 10.0.1.0 and Adobe Reader 11.0.10 $\endgroup$ – Wouter Apr 2 '15 at 11:54
  • 2
    $\begingroup$ did you Export["fig.pdf",%] or save as? If it is the latter, it is a known bug. $\endgroup$ – chris Apr 2 '15 at 12:01
  • $\begingroup$ It has been a problem in many different ways. If you search for it, it has came up many times. $\endgroup$ – Chen Stats Yu Apr 2 '15 at 12:01
  • 1
    $\begingroup$ On macosX mathematica 10.0.2 it works. $\endgroup$ – chris Apr 2 '15 at 12:19
1
$\begingroup$

This isn't a real solution to the Export As PDF problem but it is a useful workaround in case other workarounds like reverting back to MMA 10.0.1 or using Export instead of Save As don't work for you (as was the case for me since I was already in MMA 10.0.1 and had used Export). You could of course always export as a raster graphics format like JPEG or PNG but you would have to sacrifice quality which I wasn't willing to do.

Instead, you can export as EPS and compile the following TeX-file:

\documentclass{standalone}
\usepackage{graphicx,epstopdf}
\begin{document}
\includegraphics{myGraphics.eps}
\end{document}

This will generate a PDF with your graphics as well as all text (labels, legend) intact. Obviously if the idea is to incorporate the graphics into a TeX-generated PDF file anyway, you can just add the appropriate packages to your preamble and include it directly in your TeX-file.

The reason for the trouble, as I understand it, is that the PDF format will attempt to interpret symbols and work with fonts, while the EPS format will just take your graphics as they are.

$\endgroup$
  • $\begingroup$ Since you probably need a quick workaround for your project, you can also try generating the labels using LaTeX. I still find it very strange that this happens on your computer and I doubt that this is a general problem that happens with every installation of 10.0.1 on Windows ... $\endgroup$ – Szabolcs Apr 2 '15 at 13:38
  • $\begingroup$ Thanks for the link! For the project I need this for, I'm quite content to use the workaround in my answer here, since I only need the one figure and I'm not too concerned with font consistency in this case. But I'll definitely have a look at this MaTeX package for future projects! $\endgroup$ – Wouter Apr 2 '15 at 14:04
  • 1
    $\begingroup$ would it not be easier to use epstopdf to convert eps to pdf than having to install Latex and compile a document just to do this conversion? There is also many free online sites that converts eps files to pdf. This is assuming the goal is just to convert eps to pdf. $\endgroup$ – Nasser Apr 2 '15 at 21:26
  • $\begingroup$ @Nasser Yeah I guess you could just convert eps to pdf without LaTeX as well. :) $\endgroup$ – Wouter Apr 3 '15 at 11:34
1
$\begingroup$

Try to avoid transparent Ticks, or FontSize -> 0, probably this is a problem for PDF. Instead you can define your Ticks directly without Labels, if you want to have them like that.

V[r_] := Exp[-2 (r - 1)] - 2 Exp[-(r - 1)]
p = Plot[V[r], {r, 0, 5}, 
Ticks -> { {#, ""} & /@ Range[0, 5, .5], {#, ""} & /@ 
 Range[-1, 1, .25]},

AxesLabel -> {"r", "V[r]"}, 
AxesStyle -> Arrowheads[0.035], ImageSize->500]

Export["morse-potential.pdf", p, "PDF", ImageSize -> 500]

Try also to set a fixed ImageSize at least in your Export. I hope this helps, but i could not reproduce this problem on my system.

Hint: Its easier to give the AxesLabels as strings.

EDIT:

maybe this is easier to read and to modify:

Ticks -> {Table[{x,""},{x,0,5,.5}], Table[{y,""},{y,-1,1,.25}]}

EDIT2:

Have you tried changing the FontFamilie?

 SetOptions[Plot, BaseStyle -> {Large, FontFamily -> "Times", Italic}]
$\endgroup$
  • $\begingroup$ Well the problem persisted if I left out the optional arguments in the Plot command so I don't think the Transparent Ticks or 0 Fontsize are causing problems in this case. Also, giving the labels as strings only made things worse: every symbol is then rendered as one of those "L" looking objects in my examples. This makes me suspect it's a problem with fonts... But thanks for the tip on the Ticks without Labels, that will be most useful :) $\endgroup$ – Wouter Apr 2 '15 at 13:25
  • $\begingroup$ @Wouter year try to play around with FontFamilies. e.g. SetOptions[Plot, BaseStyle -> {Large, FontFamily -> "Times", Italic}] $\endgroup$ – sacratus Apr 2 '15 at 13:27
  • $\begingroup$ The Times FontFamily doesn't work either, but I'll keep trying a few others... $\endgroup$ – Wouter Apr 2 '15 at 13:31
  • 1
    $\begingroup$ @Wouter i can only recommend you to contact WRI directly. Make a bugreport on this at: -------service AT wolfram DOT com--------- I recently made a bugreport and got a very nice answer 3 days later. The seem to be happy if users help to improve Mathematica. You should tell them your Mathematica-Version and Operating Sytem, visible by $Version. You can also attach a notebook to make a clear example. good luck $\endgroup$ – sacratus Apr 2 '15 at 13:37

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.