1
$\begingroup$

I'm generating graphs with descriptions for upload to a website that only accepts raster image files. I can produce what I'm looking for in Mathematica 12.0's font-end using either Labeled or Column, but when I export the results as high-resolution raster images, a lot of white space is included around the descriptions.

Here are some examples:

Labeled

Framed@Labeled[
  Plot[{Sin[x], Cos[x]}, {x, 0, 6 \[Pi]}, PlotTheme -> "Detailed", 
   ImageSize -> Large, LabelStyle -> Directive[Black, Larger], 
   PlotLabel -> "Descriptive Plot Title", 
   PlotLegends -> {"First Function Description", 
     "Second Function Description"}, 
   FrameLabel -> {None, "Verical Axis Label"}],
  "label label label label label label label label label label label 
label label label label label label label label label label label 
label label label label label label label label label label label 
label label label label label label label label label label label 
label label label label label label label label label label label 
label label label"]

produces this in the front-end:

enter image description here

But

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

generates this instead:

enter image description here

Similarly, Column

Column[{Plot[{Sin[x], Cos[x]}, {x, 0, 6 \[Pi]}, 
   PlotTheme -> "Detailed", ImageSize -> Large, 
   LabelStyle -> Directive[Black, Larger], 
   PlotLabel -> "Descriptive Plot Title", 
   PlotLegends -> {"First Function Description", 
     "Second Function Description"}, 
   FrameLabel -> {None, "Verical Axis Label"}],
  "label label label label label label label label label label label 
label label label label label label label label label label label 
label label label label label label label label label label label 
label label label label label label label label label label label 
label label label label label label label label label label label 
label label label"}, Frame -> All]

produces this in the front end:

enter image description here

but

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

generates this instead:

enter image description here

Exporting as PDFs gives what I'm looking for, and of course, I can crop the PNGs, but I prefer not having to do any post-processing after exporting. So, can anyone tell me how to get Export to reproduce what I'm seeing in the front-end?

Thanks in advance!

$\endgroup$

1 Answer 1

1
$\begingroup$

On Mathematica 12.2, your first example exported without any problem even on higher than 300 but on your second example, the problem shows up not in the vertical direction but in horizontal!

First example

ImageResolution : 300 enter image description here

Second example

with or without specifying ImageResolution:

enter image description here

It seems that it somehow conflicts with "label label ...". If you apply Text to "label label ...", the problem disappears:

enter image description here

$\endgroup$
2
  • $\begingroup$ Interesting. I'll check out Text and see what happens. Thanks! $\endgroup$ Commented Mar 11, 2021 at 17:15
  • $\begingroup$ I'm currently running version 12.1, and with or without Text, everything exports just fine! So, this seems to be a moot problem for now. And I've been post-processing all this time, anyway, to cap the filesize. (Perhaps I should investigate doing that directly from Mathematica...) Nonetheless, since this is the only answer this question has received since I posted it ten months ago, I'll go ahead and award it the win. Thanks! $\endgroup$ Commented Mar 11, 2021 at 17:37

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.