Sign up ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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


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?

share|improve this question
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 at 15:20

1 Answer 1

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@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


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.

share|improve this answer
I'd say Show[] is more idiomatic tho; it's precisely the function intended for post hoc changes of graphics settings. – J. M. Sep 1 at 7:31

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.