1
$\begingroup$

I would like to save a series of graphics of a function as pictures. But the problem is that I can't manipulate the name of the graphs, because of that only the last graphics in the series is saved.

How could the whole series of graphics be saved?

ClearAll["Global`*"]

gr[B_, i_] := B*2*i^2

For[i = 1, i < 5, i++,
 GE[i_] := Table[{B, gr[B, i]}, {B, 0, 9, 1}];
 Export["C:/.../graphic.pdf", 
  ListPlot[Table[{GE[i][[l, 1]], GE[i][[l, 2]]}, {l, 1, 10}], 
   PlotRange -> All]]]
$\endgroup$

2 Answers 2

3
$\begingroup$

You could use Use StringJoin (<>) and ToString to give each plot a separate filename based on i

Export["C:/.../graph"<>ToString[i]<>".pdf",...]

Edit: building off Nasser's answer, it probably is just easier to put everything on one plot:

GE[i_] := Table[{B, gr[B, i]}, {B, 0, 9}];
p= ListPlot[ Table[GE[i], {i, 5}], PlotLegends -> Automatic]
Export["filepath/figName.pdf",p]

enter image description here

$\endgroup$
2
$\begingroup$

I would not do things like this, but this makes your code at least work. More functional style can be done on this. ps. also avoid For. I assume you want all plots in one pdf file.

GE=First@Last@Reap@Do[
   Sow[Table[{B,gr[B,i]},{B,0,9,1}]]
   ,
   {i,1,4}
];
p=Table[Table[{GE[[i,l,1]],GE[[i,l,2]]},{l,1,10}],{i,1,4}]
Export["p.pdf",ListPlot[ p]]

enter image description here

$\endgroup$
0

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.