10
$\begingroup$

I am trying to export a plot as an image. My actual plot uses Show to combine a ListPlot and several Plots, with a common legend. The code below is a dummy version that produces the same problem:

Labeled[Legended[
Show[Plot[t/25, {t, 10, 50}, PlotRange -> {{10, 45}, {0.4, 1.7}}, 
PlotStyle -> {{Red}}, LabelStyle -> "Text", Frame -> True, 
ImageSize -> {800, 500}]], 
Placed[PointLegend[{Red}, {"Model"}, LegendMarkers -> {None}, 
Joined -> True, LegendFunction -> "Frame"], {0.75, 
0.25}]], {Style["Long-ish title to illustrate the point", 
"Subsection"], Style["Y axis Label", "Subsubsection"], 
Style["X axis label", "Subsubsection"]}, {Top, Left, Bottom}, 
RotateLabel -> True, ImageMargins -> 5]

It renders just fine within the Mathematica notebook, but when I export it:

Export["test.png",%,ImageResolution->300]

The top label starts word-wrapping for some reason, but only in the exported file:

example of the problem

I have tried disabling word wrap in the Format menu, searched for options on text-wrap, changing to a different export format, etc.

What causes the export rendering to be different than the notebook?

$\endgroup$
3
  • 3
    $\begingroup$ Related: 75556 $\endgroup$
    – SquareOne
    Commented Oct 30, 2015 at 17:22
  • $\begingroup$ Thanks! I didn't realize it was a new (v10) option. $\endgroup$
    – cjdrover
    Commented Oct 30, 2015 at 20:33
  • $\begingroup$ Thanks to you it is more clear why they introduced this new option ;) I wonder then if the problem exists for v<10 ... If anyone can confirm ? $\endgroup$
    – SquareOne
    Commented Oct 30, 2015 at 20:47

1 Answer 1

8
$\begingroup$

What's the line about finding something as soon as you buy a replacement? Is there an equivalent for StackExchange questions?

This did the trick:

Export["test.png", %, ImageResolution -> 300, 
ImageFormattingWidth -> \[Infinity]]
$\endgroup$
3
  • $\begingroup$ Well, there's always the online forum standard, "The power of posting." $\endgroup$
    – march
    Commented Oct 30, 2015 at 17:14
  • $\begingroup$ I'm new to this forum and I don't know how I can comment on your answer. Feel free to delete this comment but I would really appreciate your help. Do you by any chance know how to extend your solution when exporting to all other formats, particularly the .eps and .pdf formats? Your solution works fine for .png, but I really need to export with .eps and .pdf. I am using Labeled like you in my plot, then I am trying to export but the text keeps wrapping. Thanks for your time. $\endgroup$
    – user41473
    Commented Jul 5, 2016 at 14:23
  • $\begingroup$ @ccam0062 I haven't been able to replicate this problem using a PDF export with my test. Do you have a code snippet demonstrating the problem? $\endgroup$
    – cjdrover
    Commented Jul 6, 2016 at 20:06

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.