# How can I use sequence in plotting domain?

I would like to plot a function but have a domain defined elsewhere as follows:

xrange = Sequence[0, 2π];
Plot[Sin[x], {x, xrange}]


However, this doesn't work resulting in the error Range specification {x, xrange} is not of the form {x, xmin, xmax}. I've tried to put an Evaluate around {x, xrange} but Mathematica was not impressed.

I can think of two easy workarounds:

xrange = {0, 2π};
Plot[Sin[x], {x, xrange[], xrange[]}]
Plot[Sin[x], Evaluate[{x, ##} & @@ xrange]]


While these are fine solutions, they involve changing xrange to a List in a place where Sequence seems to fit perfectly. Is there a Sequence solution that I can use?

• closely related: 1929
– Kuba
Jun 17 '15 at 9:26
• Cleaner: Plot[Sin[x], {x, ##}] & @@ {0, 2 π}. Jun 17 '15 at 9:51

It would be also nice to preserve scoping of x by Plot so:

xrange = Sequence[0, 2 \[Pi]];
x = 1;
Plot[Sin[x], {x, ##}] &[xrange] {xrange} /. {r__} :> Plot[Sin[x], {x, r}]

• Ah, now I understand. If x is define somewhere then @m0nhawk's solution fails? Jun 17 '15 at 9:28
• @JeffDror Yes, unfortnately. Evaluate prevents x from being properly scoped.
– Kuba
Jun 17 '15 at 9:29
• What if you use With[] for the insertion? Jun 17 '15 at 9:53
• @J. M. Sequence head will be there and Plot will still think it is only one argument. Something like in the linked topic.
– Kuba
Jun 17 '15 at 9:55
• Ooh, forgot that thread. Thanks for the reminder! Jun 17 '15 at 9:57

And what Mathematica version you have?

This works for me in Mathematica 10.0.2:

xrange = Sequence[0, 2 \[Pi]];
Plot[Sin[x], Evaluate@{x, xrange}]

• Hmm, this actually does seem to work now (Mathematica 10.0.0 Linux) . I was sure that I tried this... Thanks for your response. Jun 17 '15 at 9:24
• @JeffDror xrange = Sequence[0, 2 \[Pi]]; x = 1; Plot[Sin[x], Evaluate@{x, xrange}]
– Kuba
Jun 17 '15 at 9:27