8
$\begingroup$

When displaying graphics in the Mathematica front end, and leaving ImageSize at the default, the result will always keep its previous size.

For example,

  • Plot[Sin[x], {x, 0, 5}] produces an output 360 pixels wide (the default size).
  • Resize the plot with the mouse to make it bigger.
  • Change the input to Plot[Sin[x], {x, 0, 10}] and re-evaluate it.
  • The output figure remains at its manually set size and won't revert to 360 pixels wide.

If we were to use Plot[Sin[x], {x, 0, 5}, ImageSize -> 500] instead, then the size of the output would be re-set to 500 pixels every time this command is re-evaluated.

ImageSize -> Inherited will generally allow this behaviour.

Question:

How can I create a function that will output graphics at sizes larger than 360 pixels by default, yet when re-sizing the output manually and re-evaluating the function, the manually set size will be kept?

I do not wish to change the default output size for other functions.

$\endgroup$
3
  • $\begingroup$ Does this work?: Edit the stylesheet, create a style "Graphics"; in the Options inspector, change the ImageSize setting under GraphicsBoxOptions to 500 (or whatever). Alternatively, create a new style "Foo" and use BaseStyle -> "Foo" in your Graphics. $\endgroup$
    – Michael E2
    Aug 9, 2014 at 18:35
  • 2
    $\begingroup$ Maybe the second alternative "Foo" is what you're after. The first changes it for all Graphics. -- Actually, Plot[..., BaseStyle -> {GraphicsBoxOptions -> {ImageSize -> 500}}] seems to work. (Maybe?) $\endgroup$
    – Michael E2
    Aug 9, 2014 at 18:44
  • $\begingroup$ @MichaelE2 Nice work Michael. I was just trying to figure out how scope GraphicsBoxOptions when I saw your comment. $\endgroup$
    – Mr.Wizard
    Aug 9, 2014 at 20:05

1 Answer 1

7
$\begingroup$

The option GraphicsBoxOptions -> {ImageSize -> 500} can be set for the plot in several ways. (The option PreserveImageOptions is the one that controls what happens when the output cell is replaced. By default, the current size in output cell is preserved.)

Stylesheet

One can create a new style, say, "LargeImageSize" by editing the stylesheet (menu Format > Edit Stylesheet...) and entering name LargeImageSize into the "Enter a style name:" input field and pressing return. The select the style cell and open the Option Inspector (menu Format > Option Inspector...). In the search field of the Option Inspector, enter GraphicsBoxOptions and look for ImageSize. Edit the option to the desired size.

Alternatively, the cell expression in the stylesheet (menu Cell > Show Expression) can be edited to look like this:

Cell[StyleData["LargeImageSize"],
 MenuSortingValue->10000,
 GraphicsBoxOptions->{ImageSize->500}]

Then the style can be used with Plot and other Graphics using the BaseStyle option:

Plot[Sin[x], {x, 0, 5}, BaseStyle -> "LargeImageSize"]

Using BaseStyle directly

One need not deal with stylesheets. One can pass the option directly through BaseStyle:

Plot[Sin[x], {x, 0, 5}, BaseStyle -> {GraphicsBoxOptions -> {ImageSize -> 500}}]

Using Style

One can also use Style to post-process the graphics. Either

Style[Plot[Sin[x], {x, 0, 5}], "LargeImageSize"]

or

Style[Plot[Sin[x], {x, 0, 5}], GraphicsBoxOptions -> {ImageSize -> 500}]
$\endgroup$

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.