Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to make easy to change the variable for which I am making a set of plots. Say I want to plot Sin, Tan, Cos and other functions of the same argument. To quickly switch from plotting it as function of x or y I wanted to use a "dummy" plot variable var and assing it to y or x depending on the need.

x = 1; var = y;
Plot[Sin[x*y], {var, 1, 2}]
Plot[Tan[x*y], {var, 1, 2}]
Plot[Cos[x*y], {var, 1, 2}]
Unset[{x, y, var}];

Unfortunately this doesn't quite works because var in the range specification {var,1,2} is not evaluated.

Any suggestions?

share|improve this question
Evaluate@{var, 1, 2}... – ciao May 5 '14 at 7:53
great! it works, but what is the difference with respect to Evaluate[var] which was my trial before posting here? – Roberto Franceschini May 5 '14 at 10:16
I can't check it but as far as I remember Evaluate works only on first level. – Kuba May 5 '14 at 13:37

You need to force evaluation of the x interval list:

x = 8; var = y;
Plot[Sin[x*y], Evaluate@{var, 1, 2}]
Plot[Tan[x*y], Evaluate@{var, 1, 2}]
Plot[Cos[x*y], Evaluate@{var, 1, 2}]
Unset[{x, y, var}];


share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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