6
$\begingroup$

I'm creating a lot of graphics, which I save in PDF format for later use in LaTeX. I have currently two issues.

  1. When I create a graphic and then export it to PDF, a white space appears on the side of the graphic. After some head knocking, I figured out it is because of the legend that I use. Apparently, though I have specified legend placement on the upper-right corner of the plot, the PostScript printer still interprets Legended as if the legend was placed on the side of the graph and accounts for the space appropriately. Is there any way to work around this?

  2. How do I specify fonts to be used for axes labels and legend entries in 'printout' environment. When I plot graphics in working environment, the fonts used are Helvetica. However, when I export them in the Printout environment (default export environment) it always uses some Mathematica Sans font which Adobe Illustrator does not recognize. (OK, now we can discuss how Adobe Illustrator is unable to render an embedded font, but that is another issue).

Any feedback is appreciated.

P.S. It is not an option to use some other environment for exporting because doing so creates a chain of other issues with proper rendering of figures.

Edit: Below is example of the failed export. What can not be seen is that fonts used for legend and frame tick labels are wolfram proprietary. I added a frame so the image borders are easier to see. enter image description here

And for those interested, here is the code used to produce the image.

frame[legend_] := Framed[legend, FrameStyle -> Directive[Black, Thin], FrameMargins -> 0, Background -> White]
a = {{0, -\[Omega]^2}, {1, 0}};
b = {{g \[Omega]}, {0}};
c = {{1, 0}, {0, 1}};
d = {{0}, {0}};
StateSpaceModel[{a, b, c, d}]
SystemsModelFeedbackConnect[%, {1, 1}]
TransferFunctionModel[%, s]
BodePlot[% /. {g -> 0.1, \[Omega] -> 1}, {0.1, 10}, GridLines -> Automatic, ImageSize -> Medium, PlotLabel -> {"Amplitude Plot", "Phase Plot [degrees]"}, FrameLabel -> {{None, None}, {"\[Omega] [rad]", None}}, PlotStyle -> Thin, PlotLegends -> Placed[LineLegend[{"\!\(\*SubscriptBox[\(H\), \(1\)]\)(s)", "\!\(\*SubscriptBox[\(H\), \(2\)]\)(s)"}, LegendFunction -> frame], {0.97, 0.95}]]
Export["bodeplot.pdf", %]
$\endgroup$
1
  • 1
    $\begingroup$ Can you give a simple example of a graph whose export fails? $\endgroup$
    – mikado
    Nov 5, 2016 at 6:56

1 Answer 1

2
$\begingroup$

Initially, I thought the problem is with BodePlot with Legend, but as ercegovac pointed out, problem is with exporting as pdf. There are two possible way out.

  1. Use Rasterize

    frame[legend_] := Framed[legend, FrameStyle -> Directive[Black, Thin], FrameMargins -> 0, Background -> White]
    a = {{0, -\[Omega]^2}, {1, 0}};
    b = {{g \[Omega]}, {0}};
    c = {{1, 0}, {0, 1}};
    d = {{0}, {0}};
    StateSpaceModel[{a, b, c, d}]
    SystemsModelFeedbackConnect[%, {1, 1}]
    plot=TransferFunctionModel[%, s]
    BodePlot[plot /. {g -> 0.1, \[Omega] -> 1}, {0.1, 10}, GridLines -> Automatic,
    ImageSize -> Medium, PlotLabel -> {"Amplitude Plot", "Phase Plot [degrees]"}, 
    FrameLabel -> {{None, None}, {"\[Omega] [rad]", None}}, PlotStyle -> Thin, 
    PlotLegends -> Placed[LineLegend[{"H1(s)", "H2(s)"}, LegendFunction -> frame], {0.97, 0.95}]]
    
    Export["bodeplot.pdf", Rasterize[%, RasterSize -> 1000]]
    

With a large RasterSize is will look nice.

  1. Use Inset

    BodePlot[plot /. {g -> 0.1, \[Omega] -> 1}, {0.1, 10}, 
    GridLines -> Automatic, PlotStyle -> {Red, Blue}, ImageSize -> Medium, 
    PlotLabel -> {"Amplitude Plot", "Phase Plot [degrees]"}, 
    FrameLabel -> {{None, None}, {"\[Omega] [rad]", None}}, 
    PlotStyle -> Thin, 
    Epilog -> Inset[LineLegend[{Red, Blue}, {Style["H1(s)" 12, FontFamily -> "Times"], 
    Style["H2(s)" 12, FontFamily -> "Times"]}, LegendFunction -> frame], Scaled[{.8, .8}]], 
    BaseStyle -> Directive[12, FontFamily -> "Times"]]
    
    Export["bodeplot.pdf", %]
    

enter image description here

$\endgroup$
3
  • $\begingroup$ I would not say it is about BodePlot. If you display the InputForm, for my approach the underlying expression has the form "Legended[Grid[{{Graphics..." while in your case there is "Grid[{{Graphics[...>>intermittent expressions<< ...Epilog->Inset[LineLegend[{Red, Blue}, {"H1(s)", "H2(s)"}, LegendFunction -> frame], Scaled[{.9, .9}]]" As you can see, in my case Legended is wrapped around underlying expresion. Hence it has to do something with PostScritp interprentation of the whole expression during printing to PDF. However, thank you for your answer, your way works well for me. $\endgroup$
    – ercegovac
    Nov 5, 2016 at 14:59
  • $\begingroup$ Any thoughts on how to address the font issue? I do not know which style is used for printing legend and frame tick labels. $\endgroup$
    – ercegovac
    Nov 5, 2016 at 15:03
  • $\begingroup$ @ercegovac, you are right. I modified my answer. $\endgroup$
    – Sumit
    Nov 5, 2016 at 16:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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