Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #1947
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeder.news-service.com!xlned.com!feeder5.xlned.com!feed.xsnews.nl!border-1.ams.xsnews.nl!206.55.64.80.MISMATCH!newspump.sol.net!posts.news.twtelecom.net!nnrp2.twtelecom.net!not-for-mail |
|---|---|
| From | "Christopher O. Young" <cy56@comcast.net> |
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Workaround for Plot[ ] and color via PlotStyle |
| Date | Thu, 28 Apr 2011 10:34:16 +0000 (UTC) |
| Organization | Steven M. Christensen and Associates, Inc and MathTensor, Inc. |
| Sender | steve@smc.vnet.net |
| Approved | Steven M. Christensen <steve@smc.vnet.net>, Moderator |
| Message-ID | <ipbfr8$ac7$1@smc.vnet.net> (permalink) |
| Lines | 94 |
| NNTP-Posting-Date | 28 Apr 2011 09:35:00 GMT |
| NNTP-Posting-Host | b65042e2.news.twtelecom.net |
| X-Trace | DXC=gcgAl:8HON:E@ZX[:2Fm`8C_A=>8kQj6=;[h;PUXBgb4AbB79SZHZ=<EFiONJ7[Go6@^FAJ29BLJ1 |
| X-Complaints-To | abuse@twtelecom.net |
| Xref | x330-a1.tempe.blueboxinc.net comp.soft-sys.math.mathematica:1947 |
Show key headers only | View raw
As a previous poster showed, Plot is a little inconsistent when it comes to
mapping colors via PlotStyle.
Plot[
{
a x /. {a -> 1},
a x^2 /. {a -> 1},
a x^3 /. {a -> 1}
},
{x, 0, 2},
PlotStyle -> {Red, Green, Blue}
]
works OK but
Plot[
{
a x,
a x^2,
a x^3
} /. {a -> 1},
{x, 0, 2},
PlotStyle -> {Red, Green, Blue}
]
just produces blue plots.
So I tried to figure out to work from the fully written-out form:
Show[
Plot[y = x, {x, -5, 5}, PlotStyle -> {Thick, Red}],
Plot[y = x^2, {x, -5, 5}, PlotStyle -> {Thick, Yellow}],
Plot[y = x^3, {x, -5, 5}, PlotStyle -> {Thick, Blue}]
]
The above works fine, but is very redundant.
A Table will streamline the above commands:
Show[
Table[
Plot[
y = x^k, {x, -5, 5},
PlotStyle -> {Thick, Hue[0.5 (k - 1)/3]}
],
{k, 1, 3}]
]
Does anybody know how to go through a list of colors via the k index?
At any rate, if you're a big fan of postfix notation, the following can be
rewritten in stages, as:
Table[
Plot[
y = x^k, {x, -5, 5},
PlotStyle -> {Thick, Hue[0.5 (k - 1)/3]}
],
{k, 1, 3}
] // Show
Plot[
y = x^k, {x, -5, 5},
PlotStyle -> {Thick, Hue[0.5 (k - 1)/3]}
]~Table~{k, 1, 3}\
// Show
And, finally:
(y = x^k //
Plot[
#, {x, -5, 5},
PlotStyle -> {Thick, Hue[0.5 (k - 1)/3]}
] &)\
~Table~{k, 1, 3}\
// Show
Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread
Workaround for Plot[ ] and color via PlotStyle "Christopher O. Young" <cy56@comcast.net> - 2011-04-28 10:34 +0000
csiph-web