I've generated a bunch of graphics using ContourPlot wich, given the nature of my problem, take a long time to create, and I was wondering if there is a way to save the object (not the image) to a file so I can retrive it later to manipulate, i.e. use Show, change colors, add text, etc.

For example, suppose I define something like

conic = ContourPlot[x^2/9 + y^2/16, {x, -10, 10}, {y, -10, 10}, 
    ContourStyle -> Red, ContourShading -> None, Contours -> 15, 
    Axes -> True, AxesLabel -> {x, y}]

then by doing


I can see the objetc:

enter image description here

Now, what I'd like to do is save the object in such way that I'll be able to change the color from red to blue, the labels, the aspect ratio, etc. by just importing it and modifying the proper options without having to calculate it again.

I guess a rudimentary solution would be to export the object to a txt file, and later import it, manipulate it and then use ToExpression, but I was wonderign if there is a more "within" approach.

I hope this isn't a duplicate. I've tried to search for the answer but the keywords save and graphics made it impossible.

  • 1
    $\begingroup$ it seems you cat do conic>>"afile.m"; and newconic=<<"afile.m". Even more simply, can save the notebook, quit mathematica; open it later and via cut and paste assign it to a new variable; say plot=< your plot > and play with it. Does this answer your question? $\endgroup$ – chris Oct 3 '12 at 20:02

You could use Put and Get:

conic = ContourPlot[x^2/9 + y^2/16, {x, -10, 10}, {y, -10, 10}, 
  ContourStyle -> Red, ContourShading -> None, Contours -> 15, 
  Axes -> True, AxesLabel -> {x, y}]

conic >> "conicfile";

(* later... *)

con = << "conicfile";

con /. Red -> Blue
  • $\begingroup$ I said it first ;-) $\endgroup$ – chris Oct 3 '12 at 20:05
  • $\begingroup$ Thanks a lot, I knew it was a stupid question! $\endgroup$ – Pragabhava Oct 3 '12 at 20:08
  • $\begingroup$ There are no stupid questions! I didn't know either (and I always find the non-textual commands (>>, //, :>, [[]], etc.) no be some sort of arcane magic I didn't learn :( $\endgroup$ – JorgeGT Oct 4 '12 at 7:29

As far as I know, they're never images in the first place unless you explicitly Rasterize them. When you load the notebook, Mathematica is building it up from the FullForm structure. Open up a Mathematica notebook in Notepad and you'll see that it's just a bunch of Mathematica structure, no images. So Mathematica already does what you expect.

If the object is very large though, one option is Export["c:/myfile.mx", conic] which saves it in a raw Mathematica binary format that you can later read in with conic = Import["c:/myfile.mx"]. I'm not sure this is strictly advantageous, though. Mostly it will help load the object faster.

  • $\begingroup$ Thats nice to know. The thing is I have hundreds of this "images", so displaying all of them in the notebook is out of the question, but I can easily import them as you suggest. $\endgroup$ – Pragabhava Oct 3 '12 at 22:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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