Search code examples
plotexportwolfram-mathematicafilenames

Mathematica - export multiple plots, each with different name (depending on variables used in plot)


I'm new to Mathematica. I'm trying to produce whole lotta plots, but I don't know how to make Mathematica name them after variables. Here for example I have code producing sine plots for different coefficients infront of x variable:

d = 2;
For[n = 1, n <= 3, n = n + 1, {Do[Print[Plot[Sin[n*x] + d, {x, 0, 6 Pi}]]], Export["E:\\plots\\a.pdf", Plot[Sin[n*x] + d, {x, 0, 6 Pi}]]}]

And in program it produces 3 plots, and each time each plot is exported to a.pdf. Sadly every next time it is overwritten, so I end up with single a.pdf plot when n = 3.

Here is what I would like to achieve. After running program it would produce me 3 plots of names:

S, n=1, d=2.pdf
S, n=2, d=2.pdf
S, n=3, d=2.pdf

or

S n1 d2.pdf
S n2 d2.pdf
S n3 d2.pdf

Solution

  • Something like this perhaps ?

    Do[Export["Plot" <> ToString[n] <> "_" <> ToString[d] <> ".pdf", 
           Plot[Sin[n*x] + d, {x, 0, 6 Pi}]], {n, 1, 3}]
    

    You'll probably want to adjust the file names.