# How to extract a picture from Manipulate, without frame, sliders and axes?

I would like to extract some pictures from a Manipulate that uses a slider, but when I do it from the pop-up menu, I get all the frame and slider with it. How can we export the picture (to PNG, say), for a given slider value (say $$k = 0.5$$, for the example below), without the Manipulate frame, slider, and even without the axes and ticks?

And probably trickier: how can we extract the graphics with an higher resolution than what the Manipulate shows? (say 1024 x 1024 pixels in PNG format, instead of the lower resolution of 600 below).

Here's a semi-cool MWE to play with:

Manipulate[
ContourPlot[
Cos[x + y] Sin[k x - 3 y],
{x, -2, 2},
{y, -2, 2},
PlotPoints -> 20,
PlotRange -> {{-2, 2}, {-2, 2}},
Axes -> True,
AxesOrigin -> {0, 0},
AxesStyle -> Directive[GrayLevel[0.5]],
AxesLabel -> {
Style["X",  Bold, 14],
Style["Y",  Bold, 14]
},
ColorFunction -> "Rainbow",
ContourStyle -> Black,
Contours -> Automatic,
ImageSize -> 600
],
{
k, -5, 5, 0.1,
ImageSize -> Large,
Appearance -> {"Labeled", "Closed"},
AppearanceElements -> {"InputField", "Slider"}
},
ControlPlacement -> Bottom,
FrameMargins -> None,
FrameLabel ->  {None, None,
Style["Some Funny Title", Bold, 14, FontFamily -> "Helvetica"]}
]

• I click on the graphics and Edit > Copy. You can also click on the circled + button in the upper-right corner of the Manipulate frame and 'Paste Snapshot". For output, use Export on the copied graphics. – Michael E2 Dec 8 '20 at 20:00
• @MichaelE2, the problem with this method is you can't choose the format (PNG say) and resolution. Or maybe there is but I don't know it. – Cham Dec 8 '20 at 20:06
• @MarcoB, I understand for the resolution. I was extracting the picture by hand, by re-running the Manipulate code with a few modifications (remove axes, etc), but it's clumsy. – Cham Dec 8 '20 at 20:08
• One of the ways I use quite often is to just go Manipulate[plt = ContourPlot[...], ...]. Then, when you change your sliders, the new image is stored to plt. Then, Export["path/plot.png", plt, ImageSize -> {1024, 1024}]. The resolution in your code isn't 600, that's just a width (well, I suppose it might end up being the resolution if there are no other options given on export). I usually choose a target resolution when exporting and ignore the size like Export["path/plot.png", plt, ImageResolution -> 300]. – MassDefect Dec 8 '20 at 20:08
• You'll want to set TrackedSymbols in @MassDefect 's solution, or you'll recompute the plot. – Michael E2 Dec 8 '20 at 20:16

Manipulate[
plt = ContourPlot[
Cos[x + y] Sin[k x - 3 y],
{x, -2, 2}, {y, -2, 2},
PlotPoints -> 20,
PlotRange -> {{-2, 2}, {-2, 2}},
Axes -> True,
AxesOrigin -> {0, 0},
AxesStyle -> Directive[GrayLevel[0.5]],
AxesLabel -> {Style["X", Bold, 14], Style["Y", Bold, 14]},
ColorFunction -> "Rainbow",
ContourStyle -> Black,
Contours -> Automatic, ImageSize -> 600
],
{k, -5, 5, 0.1, ImageSize -> Large, Appearance -> {"Labeled", "Closed"}, AppearanceElements -> {"InputField", "Slider"}},
ControlPlacement -> Bottom,
FrameMargins -> None,
FrameLabel -> {None, None, Style["Some Funny Title", Bold, 14, FontFamily -> "Helvetica"]}
]

Export["~/Desktop/test.png", plt, ImageSize -> {1024, 1024}]

(* or *)

Export["~/Desktop/test.png", plt, ImageResolution -> 300]

(* EDIT *)

Export["~/Desktop/test.png", plt[[1]]//Graphics, ImageSize -> {1024, 1024}]


This saves the frame generated by the slider setting to a variable called plt. Every time the slider changes, plt is updated. Then, I typically use the Export command so that I can more easily control the various parameters. A bit of an aside: one export parameter that I quite like is Background -> None. Not really relevant here, but it allows you to export PNG images with no background. Looks really slick when adding to a poster or presentation if the graphics have sufficient contrast with the background.

To get just the graphics form the ContourPlot I used @andre314's method of taking the first element of plt and turning it into a graphic, namely plt[[1]]//Graphics.

The result of the above code with ImageSize -> {1024, 1024} is:

The result of the final export statement from above is:

• Wooaa! This is cool! – Cham Dec 8 '20 at 20:22
• @Cham Although I just realized that you asked to export with no ticks or axes labels either. You can actually just use the last step shown by Andre314 above. I'll add that to my answer (with attribution). – MassDefect Dec 8 '20 at 20:26
• It works, and it's neat!! This is awesome! Apparently, it doesn't work of Plot3D, though. – Cham Dec 8 '20 at 20:38
• @Cham Plot3D gives 3d graphics. We can fix it by using Graphics3D[plt[[1]], Boxed -> False] in place of plt[[1]]//Graphics. – MassDefect Dec 8 '20 at 22:27
• Yep, it fixes this issue. Thanks a lot! – Cham Dec 8 '20 at 22:35

EDIT

I have found something simplier than my first answer:

Apply Setting to the Manipulate to obtain a normal graphic.

Then to remove all the options of this graphic, one way is to take the first part and reapply Graphic

END EDIT

Then remplace DynamicModule by With (this may not be necessary),
then the evaluation of this gives a normal Graphics. To remove all the options of this graphic, one way is to take the first part and reapply Graphic
• I've been trying to remember what the name of Setting was. +1 – Michael E2 Dec 8 '20 at 20:52