45
$\begingroup$

I am trying to use the Export command to convert a list of plots into a *.gif file, and the command runs and executes well, but I can't find the file! Where is it supposed to go? Did it even work?

Here is my code :

  q[n_, x_] := x (1 + x)^n + x^n;
  points = Table[
     Map[{Re[#], Im[#]} &, 
   Flatten[NSolve[q[n, x] == 0, x][[All]] /. Rule -> (#2 &)]], {n, 1, 20}];

  Export["domniationrootsstargraph.gif", 
    Table[ListPlot[points[[i]], PlotRange -> {{-15, 4}, {-10, 10}}], {i, 1, 20, 1}]
        ]

Thanks in advance =)

$\endgroup$
2
  • 5
    $\begingroup$ You can specify the full path. Windows example: Export["c:\\a.gif", img] $\endgroup$ Jul 21, 2012 at 22:27
  • 1
    $\begingroup$ I added a few more tricks in the answer, I hope it helps too ;-) $\endgroup$ Jul 21, 2012 at 22:44

4 Answers 4

58
$\begingroup$

Easy to check:

Directory[]

Which in my case on Win7 gives:

"C:\Users\vitaliyk\Documents"

You can always specify a complete path to a destination you'd like to save with, for example, top menu Insert >> FilePath which will bring a standard browse-directory window:

enter image description here

This would go instead of your "domniationrootsstargraph.gif". A useful trick to know is command

SetDirectory[NotebookDirectory[]]

which will allow saving your files by default (without full-path specification) into the directory where your notebook is saved. Also to check files in the CurrentDirectory use

FileNames[]

or, for example,

FileNames["*.gif"]

for specific file types.

$\endgroup$
1
  • $\begingroup$ Thank you! Exactly what I wanted. $\endgroup$ Jul 21, 2012 at 22:27
19
$\begingroup$

Just to add a slightly different method; something I like to do, since I am fairly OCD about always working in a notebook which is already saved in some directory, is to use NotebookDirectory:

Export[NotebookDirectory[]<>"test.gif",list]

This saves your file in the same directory as your .nb file, and is fairly easy to remember in a pinch.

$\endgroup$
2
  • $\begingroup$ This only works if the Notebook has first been saved. +1 nevertheless $\endgroup$
    – Mr.Wizard
    Nov 9, 2012 at 8:47
  • $\begingroup$ As someone who has seen a friend stuggle with and be hurt by severe OCD, I ask you to please refrain from using the word as some bizarre slang for perfectionism. They are not the same at all. Using it that way makes light of a terribly real problem some people face, and promotes misconceptions about OCD. I know you probably didn't mean any harm, but just imagine someone using chronic pain as slang for laziness. It would be insulting and ignorant. $\endgroup$
    – Allison B
    Dec 12, 2022 at 16:47
12
$\begingroup$

You might try

Export[SystemDialogInput["FileSave", "domniationrootsstargraph.gif"], 
   Table[ListPlot[points[[i]], PlotRange -> {{-15, 4}, {-10, 10}}], {i, 1, 20, 1}]]

This will let you pick the directory interactively.

$\endgroup$
4
$\begingroup$

Try this, one I compiled for my thesis writing:

Export2PDF[PlotName_] := 
Module[{A = 600}, 
Export[SystemDialogInput["FileSave", 
StringJoin[{ToString[FileName], ".pdf"}]], PlotName, 
"AllowRasterization" -> True, ImageSize -> 360, 
ImageResolution -> A]]

Plot example:

Plot1 = Plot3D[
Sin[x] Sin[y], {x, -\[Pi], \[Pi]}, {y, -2 \[Pi], 2 \[Pi]}]

Output:

1

Export Code:

Export2PDF[Plot1]

Dialog Box: 2

SAVE and DONE !

3

$\endgroup$
1
  • 1
    $\begingroup$ You can also right-click the figure and choose Save As... I won't give you quite as much control over the options though. $\endgroup$
    – Szabolcs
    May 12, 2013 at 18:36

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.