14
$\begingroup$

When creating a plot in Mathematica 10 (OS X 10.9.4 and Win 7) the FrameLabel and Ticks are greyish and only the Frame itself is black (see Screenshot bellow). Only when exporting the plot to PDF all elements are black. However when I try to export the plot to PNG, then the resulting PNG looks exactly like the screenshot.

Is there a way to use the Printout style (as is used when exporting to PDF), when exporting plots to raster graphics (bitmap) formats such as PNG?

Plotting:

 plot = Plot[x^2, {x, 0, 3}, Frame -> True, 
 FrameStyle -> Directive[Thick, FontSize -> 24], 
 FrameLabel -> {"x", "y"}]

and Exporting:

 Export["plot.png", plot];
 Export["plot.pdf", plot];

Comparison

$\endgroup$

2 Answers 2

13
$\begingroup$

I had the same problem after switching to Mathematica 10. The issue here is the following:

Export uses Rasterize to create the png image. The StyleEnvironement, which is used in Rasterized, cannot be specified as an option but is given by the $FrontEnd object (not by the EvaluatingNotebook[]!). You can change the StyleEnvironement by

SetOptions[$FrontEnd, ScreenStyleEnvironment -> "Printout"]

When you use Export or Rasterize now, you will obtain the "Printout" style.

Note: This has been tested on Mathematica 10, Win7, 64bit. Other versions (Mac) might behave differently (see comments below). Consider using the $FrontEndSession object, as suggested by Michael E2 below.

Related questions on Stackexchange:

How to Rasterize in "Printout" style

https://stackoverflow.com/questions/6093559/how-to-export-graphics-in-working-style-environment-rather-than-printout )

$\endgroup$
7
  • 4
    $\begingroup$ I believe changing $FrontEnd changes the setting in init.m, and the change will persist until it is changed back. I think you ought to warn users of that. $\endgroup$
    – Michael E2
    Commented Aug 19, 2014 at 15:39
  • 1
    $\begingroup$ I verified that this is true: (FrontEnd/init.m) is modified, i.e. the proposed change is persistent! This might be desired in some cases. $\endgroup$
    – denizb
    Commented Aug 19, 2014 at 16:43
  • $\begingroup$ Yes, it might be desired. I was thinking of an unsuspecting visitor to the site being caught off-guard by it. $\endgroup$
    – Michael E2
    Commented Aug 19, 2014 at 16:59
  • 1
    $\begingroup$ There might be differences with the different versions: On my instance (MA10, Win7, 64bit) it works directly and reversibly. On my colleagues Version (MA10, Mac OS X) there seems to be issues. $\endgroup$
    – denizb
    Commented Aug 19, 2014 at 17:45
  • 1
    $\begingroup$ It might be nice to point out that the original setting is ScreenStyleEnvironment -> "Inherited". $\endgroup$
    – Michael E2
    Commented Aug 19, 2014 at 19:23
8
$\begingroup$

I could not get it to work with $FrontEnd, but setting the ScreenStyleEnvironment on $FrontEndSession worked for me. Here text cells get two different backgrounds and font sizes, depending on the environment. ("Printout" is pink and large.)

sseOpt = Options[$FrontEndSession, ScreenStyleEnvironment];
SetOptions[$FrontEndSession, ScreenStyleEnvironment -> "Printout"];
Export["file.png", Cell["Printout text", "Text"]]
SetOptions[$FrontEndSession, sseOpt];

enter image description here

Shown here using Rasterize:

enter image description here

Notes:

The switching of environments causes some dancing around in the windows. The magnification is left in the "Printout" setting until you edit the notebook, when it will change to the former setting. This seems like a bug, but it's in both V9/V10.

Changes to $FrontEnd are written in the start-up file init.m. Such changes will be permanent (until changed again, that is).

The default setting is ScreenStyleEnvironment -> "Inherited" (for both $FrontEndSession and $FrontEnd).

$\endgroup$
2
  • $\begingroup$ I was going to address the related (if not duplicate) question 10065, but I couldn't reproduce the author's problem in V10, V9, nor V8.0.4. So I'll leave my answer here for now. $\endgroup$
    – Michael E2
    Commented Aug 19, 2014 at 16:38
  • $\begingroup$ I considered, if this is a duplicate and decided that it is not, because the original question relates to Export (and only indirectly to Rasterize) $\endgroup$
    – denizb
    Commented Aug 19, 2014 at 16:42

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.