P.Escondido
P.Escondido

Reputation: 3553

How can I import .eps in Mathematica without losing the text?

I am trying to import a histogram produced by Stata as an .eps file into Mathematica, but it does not display axes' labels. That is, for some reason, Mathematica does not import .eps as but rather transforms it.

How can I avoid that? As of now, I am using plain

Import["~/hst.eps"]

Upvotes: 0

Views: 1113

Answers (2)

Alexey Popkov
Alexey Popkov

Reputation: 9425

Mathematica currently (v.9) usually cannot import textual elements from .eps files properly. One possible solution would be to export your plot as .pdf rather than .eps from you plotting software and then Import generated .pdf. If you need to import the text as text you can turn off outlining by using the "TextOutlines" -> False option.

If exporting to .pdf from your plotting software is not possible you can convert .eps to .pdf by another program and then Import generated .pdf as above. For your file orders_weekly.eps using the gsEPS2PDFEmbedFonts function and then Importing generated .pdf, I get (Mathematica 8.0.4):

gsEPS2PDFEmbedFonts["orders_weekly.eps", "orders_weekly.pdf"]
graphics=First@Import["orders_weekly.pdf"(*,"TextOutlines"->False*)];
Show[graphics, Frame -> True, PlotRange -> All, ImageSize -> Automatic]

plot

I have commented the "TextOutlines" -> False option because Mathematica 8.0.4 still imports rotated text incorrectly with it. I haven't tested it with v.9 though.


Another possibility is to convert all the glypth in the .eps file to oultines. Based on Jens Nöckel's code,

gsEPS2outlinedEPS[epsPath_String, outlinedEPSPath_String] := 
 Run["gswin64c.exe -sDEVICE=epswrite -dNOCACHE -sOutputFile=\"" <> 
   outlinedEPSPath <> "\" -q -dbatch -dNOPAUSE \"" <> epsPath <> 
   "\" -c quit"]

Here gswin64c.exe is the name of GhostScript executable for 64bit Windows systems, for Linux replace it with gs. Note that you should have GhostScript installed and configured (for Windows you should add gs\bin and gs\lib to the PATH, where gs is the top-level Ghostscript directory)

Upvotes: 0

dimitriy
dimitriy

Reputation: 9460

I had a similar problem with LateX and a pdf graph recently, which also manifested itself with the eps version. I wound up modifying the user-written graphexportpdf and things seemed to work out. Perhaps you will find this solution helpful.

Upvotes: 1

Related Questions