# Change size of a saved plot or image (post-processing)

I have many plots (that take a long time to run) and each is saved to a variable name. For simplicity, say one was:

m = Plot[Sin[x], {x, -1, 1}, ImageSize -> 600]


If I call for the plot

m


it will be presented as it should be, with ImageSize 600. I can click and drag the corners to change the size of the plot (instantaneously, so I know mathematica is not re-computing the plot, but simply adjusting the output image size continuously).

Therefore, what I wish to accomplish must be possible to do, but I don't know how to instruct mathematica to do it.

What I want is a command, something similar to, say

m /. ImageSize -> 200


etc. that can present m with a new, prescribed size, rather than manually sliding it to a new size, and certainly without having to re-compute the code that produced the saved plot. Help?

• Or just Show[m, ImageSize -> 200] – Öskå May 19 '14 at 15:28
• Steve, @Öskå is the correct answer. While using the rule method works, it depends on the internal structure of Graphics to do so. Using Show does not. Well, in the sense that you no longer have to worry about it. – rcollyer May 19 '14 at 15:30
• Awesome, thanks, Show should work for me. – Steve May 19 '14 at 15:37
• # /. (ImageSize -> (ImageSize /. Last@#)) -> (ImageSize -> 200) &[m] directly replaces the previously defined size definition in your case, as FullForm will demonstrate you. – UDB Jun 1 '14 at 21:33
• Another way: Image[m, ImageSize -> 200]. – bill s Sep 1 '15 at 15:20

## 1 Answer

There are two straight-forward ways of doing this. The first, as mentioned in the comments by Oska is

Show[m, ImageSize -> 200]


As mentioned by Guess Who It Is in a comment, this is the more idiomatic way of doing things, as this is exactly what Show is for. To understand what this does, do

Last@Normal@m


and

Last@Normal@Show[m, ImageSize -> 200]


Both have the option ImageSize -> 600 buried in the list of Options, but the second has ImageSize -> 200 prepended to the list. Plot uses the first instance of an option, so the new ImageSize overrides the original.

The second, which uses a replacement rule similar to one in a comment by UDB, is

mNew = m /. HoldPattern[ImageSize -> _] -> (ImageSize -> 200)


This replacement rule find a match for the pattern HoldPattern[ImageSize -> _] and replaces it with the new one. Now, if you do

Last@Normal@mNew


you will now find ImageSize -> 200 in the place where ImageSize -> 600 used to be.

Moral of the second story: it helps to remember that everything in Mathematica is an expression (including graphics), and so parts can be replaced with the relevant replacement rule.

• I'd say Show[] is more idiomatic tho; it's precisely the function intended for post hoc changes of graphics settings. – J. M. will be back soon Sep 1 '15 at 7:31