Rasterize uses default stylesheet if ImageSize is specified
In Mathematica 8.0.4 Rasterize[p]
uses the default styles even without ImageSize
:
$Version
SetOptions[EvaluationNotebook[],
StyleDefinitions ->
Notebook[{Cell[StyleData[StyleDefinitions -> "Default.nb"]],
Cell[StyleData["GraphicsLabel"], FontColor -> RGBColor[0, 1, 0], FontWeight -> Bold,
FontSize -> 16]}, StyleDefinitions -> "PrivateStylesheetFormatting.nb"]];
"8.0 for Microsoft Windows (64-bit) (October 7, 2011)"
p = Plot[x, {x, 0, 1}];
Rasterize[p]
Surprisingly, if we simply wrap Graphics
by Style
the Notebook's stylesheet is applied (wrapping by Pane
, Text
or Row
also work):
{Rasterize[Style[p]], Rasterize[Style[p], ImageSize -> 360]}
Unfortunately specifying the stylesheet via Style
doesn't work (checked with versions 8.0.4 and 11.0.1):
SetOptions[EvaluationNotebook[], StyleDefinitions -> Inherited]
Rasterize[Style[p,
StyleDefinitions ->
Notebook[{Cell[StyleData[StyleDefinitions -> "Default.nb"]],
Cell[StyleData["GraphicsLabel"], FontColor -> RGBColor[0, 1, 0], FontWeight -> Bold,
FontSize -> 16]}, StyleDefinitions -> "PrivateStylesheetFormatting.nb"]]]
But we can specify it as an option of Notebook
expression:
Rasterize[Notebook[{Cell[BoxData@ToBoxes@p, "Output"]},
StyleDefinitions ->
Notebook[{Cell[StyleData[StyleDefinitions -> "Default.nb"]],
Cell[StyleData["GraphicsLabel"], FontColor -> RGBColor[1, 0, 0], FontWeight -> Bold,
FontSize -> 16]}, StyleDefinitions -> "PrivateStylesheetFormatting.nb"]]]
With Mathematica version 9.0.1 I can get the result I wanted by specifying the ImageSize
as a Graphics
option, e.g. using Show
, rather than using it as an option to Rasterize
:
Rasterize[Show[p, ImageSize -> 200]]
Note that the labels are still at the size specified in the style sheet.
Interestingly, the custom style is used if the graphic is embedded in a non-graphical construct, but in this case the font is demagnified. The following all produce the same output:
Rasterize[Style[p, {}], ImageSize -> 200]
Rasterize[Magnify[p, 1], ImageSize -> 200]
Rasterize[Text[p], ImageSize -> 200]
This is consistent with the documentation for Rasterize
(the first two items under the "Properties and Relations" section) which states:
Rasterizing a graphic with a custom
ImageSize
option works by changing the graphic'sImageSize
, not by magnifying the graphic. A graphic embedded in a non-graphical construct will magnify instead.