Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Dashing with alternating colors?

115 views
Skip to first unread message

AES

unread,
Aug 20, 2007, 3:38:10 AM8/20/07
to
Any simple PlotStyle to plot a curve with segments in alternating colors?

[I can think of plotting the curve twice, in alternating colors, dashed
both times, and somehow offsetting the dashes (how to do that
accurately?) -- or plotting it solid once, then overlaying it dashed in
the other color. But a neater way?]

David Annetts

unread,
Aug 21, 2007, 5:08:14 AM8/21/07
to
Hi,

There is

ListLinePlot[Table[Sin[x], {x, 0, 2 Pi, 0.1}], Joined -> True,
PlotStyle -> Directive[Opacity[0.5], Thick], Mesh -> 10,
MeshFunctions -> {#1 &}, MeshShading -> {Red, Blue}]

>From the online help.

Helen Read

unread,
Aug 21, 2007, 5:11:16 AM8/21/07
to

Something like this?

Plot[Sin[x], {x, -2 \[Pi], 2 \[Pi]}, Mesh -> 20,
MeshFunctions -> {#2 &}, MeshShading -> {Red, Blue},
PlotStyle -> Thick]

--
Helen Read
University of Vermont

Bob Hanlon

unread,
Aug 21, 2007, 5:20:23 AM8/21/07
to
Plot[2 x^2 - 8 x - 5, {x, 0, 10},
ColorFunctionScaling -> False,
ColorFunction ->
Function[{x, y}, If[EvenQ[Round[x]], Red, Blue]]]


Bob Hanlon

DrMajorBob

unread,
Aug 22, 2007, 4:49:59 AM8/22/07
to
Or perhaps...

Plot[Sin[x], {x, 0, 2 Pi},
PlotStyle -> Directive[Opacity[0.5], Dashed, Thick],
ColorFunction -> Hue]

Bobby

On Tue, 21 Aug 2007 04:02:39 -0500, David Annetts
<davida...@aapt.net.au> wrote:

> Hi,


>
>> Any simple PlotStyle to plot a curve with segments in
>> alternating colors?
>> [I can think of plotting the curve twice, in alternating
>> colors, dashed both times, and somehow offsetting the dashes
>> (how to do that
>> accurately?) -- or plotting it solid once, then overlaying it
>> dashed in the other color. But a neater way?]
>

> There is
>
> ListLinePlot[Table[Sin[x], {x, 0, 2 Pi, 0.1}], Joined -> True,
> PlotStyle -> Directive[Opacity[0.5], Thick], Mesh -> 10,

> MeshFunctions -> {#1 &}, MeshShading -> {Red, Blue}]
>
>> From the online help.
>
>

--
DrMaj...@bigfoot.com

Brett Champion

unread,
Aug 23, 2007, 1:09:28 AM8/23/07
to
On Aug 22, 2007, at 3:43 AM , DrMajorBob wrote:

> Or perhaps...
>
> Plot[Sin[x], {x, 0, 2 Pi},
> PlotStyle -> Directive[Opacity[0.5], Dashed, Thick],
> ColorFunction -> Hue]
>

Unfortunately this doesn't dash well at the top or bottom, because of
the adaptive refinement. Since Line doesn't currently support
VertexColors, Plot with a ColorFunction generates a bunch of line
segments, each with a specific color. Then the dashing is applied
to each of those segments individually, instead of to the plot as a
whole.

Brett Champion
Wolfram Research

0 new messages