Re: and color via PlotStyle
- To: mathgroup at smc.vnet.net
- Subject: [mg118553] Re: and color via PlotStyle
- From: Bob Hanlon <hanlonr at cox.net>
- Date: Tue, 3 May 2011 05:43:16 -0400 (EDT)
I believe that more than one person have suggested use of Evaluate. Plot[Evaluate[{a x, a x^2, a x^3} /. {a -> 1}], {x, 0, 2}, PlotStyle -> {Red, Green, Blue}] Bob Hanlon ---- Dushan Mitrovich <dushanm at spinn.net> wrote: ============= Helen Read wrote: > On 4/30/2011 5:51 AM, AES wrote: > >> In article<ipe7mj$r1o$1 at smc.vnet.net>, >> Bill Rowe<readnews at sbcglobal.net> wrote: >> >> >>> >>>> Plot[{ a x, a x^2, a x^3}/. {a -> 1},{x, 0, 2}, >>>> PlotStyle -> {Red, Green, Blue}] >>>> >>> >>>> just produces blue plots. >>>> >>> Exactly as it should. >>> >> The statement "Exactly as it _should_" is open to discussion here. >> >> Consider an "ordinary user" (a user attempting to use Mathematica to do >> some simple but useful task) who is at a level of sophistication where >> he/she understands the Plot command; how to use it to plot a List of >> functions {f1,f2,f3}; the use of simple PlotStyles; and the use of the >> "\." syntax =AD=AD but has never had to encounter the concepts of Hold or >> Evaluate. >> >> After all, having a rudimentary understanding of Plot, PlotStyle, the \=2E >> syntax, and lists (which are all relatively simple, understandable, >> learnable commands that do familiar things) permits this user to do many >> useful tasks =AD=AD and to do themwithout ever having any interaction with >> the much more complex and arcane (and much less standard or familiar in >> ordinary life) concepts of Hold and Evaluate. >> >> This mythical user might then well be forgiven for thinking that the two >> commands >> >> a = 1; >> Plot[{ a x, a x^2, a x^3}, {x, 0, 2}, >> PlotStyle -> {Red, Green, Blue}] >> >> Plot[{ a x, a x^2, a x^3}/. {a -> 1}, {x, 0, 2}, >> PlotStyle -> {Red, Green, Blue}] >> >> _should_ do exactly the same thing, except that the first form will also >> obviously leave a assigned the value 1 in subsequent cells. >> >> But of course, this is not what happens, and so the user who uses the >> second form (perhaps doing so for compactness, or perhaps wanting to >> make a test Plot of their List without setting a to a fixed value) >> encounters another of the copious supply of puzzling Mathematica >> "gotchas". >> >> I'm not arguing that this outcome is in some sense "wrong", or in any >> way a bug. There may be -- probably are -- deep reasons, buried deep in >> the logic and design of Mathematica, as to why Plot has to function in >> this way (or maybe an unnecessary design decision was made that Plot >> would function in this way to simplify other aspects of Mathematica >> programming?). >> >> But it's still unfortunate that it does operate this way. Would you >> (and maybe Helen ??? in Washington) really want to argue that high >> school students, or freshman students in college, should have to first >> go through a tutorial in Hold and Evaluate (and maybe also HoldAll, >> HoldFirst, NHoldAll, HoldAllComplete, HoldRest, SequenceHold, Extract, >> and Unevaluated) before they could start plotting Lists using Plot? >> > Oh, please. Nobody needs to go through all that "before they could start > plotting Lists using Plot". > > My beginning students plot lists all the time. Normally they do it by > defining functions first, for whatever it is they are plotting. > > f[x_]:=x > g[x_]:=x^2 > h[x_]:=x^3 > > Plot[{f[x],g[x],h[x]},{x,0,2},PlotStyle -> {Red, Green, Blue}] > > (Although actually, most of them accept the default colors and rarely > bother with PlotStyle. Either way, they will get a nice plot with each > curve a different color.) > Then they might go back and edit f[x], g[x], and h[x] to make them 2x, > 2x^2, 2x^3, or what have you, and re-evaluate. A little later on (when > not exactly a newbie anymore), they might try something along these > lines, which also produces different colored curves. > > > Manipulate[ > Plot[{a x, a x^2, a x^3}, {x, -2, 2}, > PlotStyle -> {Red, Green, Blue}, PlotRange -> {-10, 10}], {a, -5, 5, > 1, Appearance -> "Labeled"}] > > > I have *never* seen a beginner try to use anything remotely like > { a x, a x^2, a x^3}/. {a -> 1} inside a Plot. But if they did, it > would not bother anybody. They would either ask why it came out that > way, or try a different way of doing it, or ignore it and move on. It's > just not a big deal. > > But I don't even show them the /. notation until there is a real need > for it. I teach them about defining functions from day one. > > -- > Helen Read > University of Vermont > So far everybody has been talking about whether the behavior is reasonable or unreasonable to expect, but nobody has (AFAIK) done the obvious, namely stated the solution to the question: Just how does one get differently-colored curves when using the '/.{a->1}'? I am a near-beginner, have run into the problem myself, and have been reading the thread hoping to learn the solution. No luck. - Dushan