For Programmers: Free Programming Magazines  


Home > Archive > Mathematica > April 2005 > plot on condition









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author plot on condition
Steven M. Christensen

2005-04-19, 8:59 am

hello
my question about plotting a list of points but with some condition depends on
the status of points in other list;
pnts={{1,2},{5,4},{3,2},{2,6},{5,3}};
cnd={7,3,5,8,3};
the condition is: plot a point in list "pnts" in Blue if the corresponding
element in list "cnd" is 3 else plot in Green
regards

yehuda ben-shimol

2005-04-20, 9:00 am

I'm not sure if you can do it directly under ListPlot, but with
combination graphics primitives and some basic programming IT IS
POSSIBLE
the following will do
Graphics[{PointSize[0.05], {If[Last[#] == 3, Green,
Red], Point[First[#]]} & /@ Thread[{pnts, cnd}]}, Axes -> True,
PlotRange -> All] // Show
This may also be generated as a function that take the data and
conditions as arguments
yehuda
> hello
> my question about plotting a list of points but with some condition depends on
> the status of points in other list;
> pnts={{1,2},{5,4},{3,2},{2,6},{5,3}};
> cnd={7,3,5,8,3};
> the condition is: plot a point in list "pnts" in Blue if the corresponding
> element in list "cnd" is 3 else plot in Green
> regards
>
>


Bob Hanlon

2005-04-20, 9:00 am

pnts={{1,2},{5,4},{3,2},{2,6},{5,3}};
cnd={7,3,5,8,3};

Show[Graphics@
{AbsolutePointSize@4,
{If[#[[1]]==3,Blue,Green],
Point@#[[2]]}&/@
Thread@{cnd,pnts}},
Frame->True,
PlotRange->{{-0.15,5.15},{-0.15,6.15}}];

or

Show[Graphics@
{AbsolutePointSize@4,
Thread@{cnd/.{3->Blue,_?NumericQ->Green},
Point/@pnts}},
Frame->True,
PlotRange->{{-0.15,5.15},{-0.15,6.15}}];


Bob Hanlon

>
> Date: 2005/04/19 Tue AM 04:55:39 EDT
> Subject: plot on condition
>
> hello
> my question about plotting a list of points but with some condition depends on
> the status of points in other list;
> pnts={{1,2},{5,4},{3,2},{2,6},{5,3}};
> cnd={7,3,5,8,3};
> the condition is: plot a point in list "pnts" in Blue if the corresponding
> element in list "cnd" is 3 else plot in Green
> regards
>
>


Jens-Peer Kuska

2005-04-20, 9:00 am

Hi,

Graphics[
MapThread[
{If[3 == #2, RGBColor[0, 0, 1], RGBColor[0, 1,
0]], Point[#1]} &,
{pnts, cnd}
], Frame -> True
] //Show

???

Regards
Jens

schrieb im Newsbeitrag
news:d42lcj$3lb$1@smc.vnet.net...
> hello
> my question about plotting a list of points but
> with some condition depends on
> the status of points in other list;
> pnts={{1,2},{5,4},{3,2},{2,6},{5,3}};
> cnd={7,3,5,8,3};
> the condition is: plot a point in list "pnts" in
> Blue if the corresponding
> element in list "cnd" is 3 else plot in Green
> regards
>



David Park

2005-04-20, 9:00 am

Needs["Graphics`Colors`"]

pnts = {{1, 2}, {5, 4}, {3, 2}, {2, 6}, {5, 3}};
cnd = {7, 3, 5, 8, 3};

plotpoints = MapThread[{If[#2 == 3, Blue, Green], Point[#1]} &, {pnts, cnd}]

Show[Graphics[
{AbsolutePointSize[5], plotpoints}],
Axes -> True,
PlotRange -> {{0, 6}, {0, 7}},
ImageSize -> 400,
Background -> Linen];

David Park
djmp@earthlink.net
http://home.earthlink.net/~djmp/




hello
my question about plotting a list of points but with some condition depends
on
the status of points in other list;
pnts={{1,2},{5,4},{3,2},{2,6},{5,3}};
cnd={7,3,5,8,3};
the condition is: plot a point in list "pnts" in Blue if the corresponding
element in list "cnd" is 3 else plot in Green
regards




bghiggins@ucdavis.edu

2005-04-20, 9:00 am

Steven, Try this

pnts={{1,2},{5,4},{3,2},{2,6}, {5,3}};
cnd={7,3,5,8,3};


Show[Graphics[MapIndexed[If[
cnd[[First[#2]]] == 3, {Blue, AbsolutePointSize[6], Point[#1]},
{Green,
AbsolutePointSize[6], Point[#1]}] &, pnts], {PlotRange ->
Automatic, AspectRatio ->
GoldenRatio^(-1), DisplayFunction :> $DisplayFunction,
ColorOutput ->Automatic, Axes ->
Automatic, AxesOrigin -> Automatic,
PlotLabel -> None, AxesLabel -> None, Ticks -> Automatic}]]

Cheers,

Brian

dh

2005-04-20, 9:00 am

As far as I know, ListPlot can only deal with one set of PlotStyles (one
color) at a time.
You can still use ListPlot to plot the axes, but you then plot the
points again in a Epilog with the needed colors. E.g.

ListPlot[pnts, Epilog -> {PointSize[0.05], MapThread[({If[#1 == 3,
Blue, Red], Point[#2]}) &, {cnd, pnts} ]}]

Sincerily, Daniel

> hello
> my question about plotting a list of points but with some condition depends on
> the status of points in other list;
> pnts={{1,2},{5,4},{3,2},{2,6},{5,3}};
> cnd={7,3,5,8,3};
> the condition is: plot a point in list "pnts" in Blue if the corresponding
> element in list "cnd" is 3 else plot in Green
> regards
>


Wolf, Hartmut

2005-04-20, 9:00 am



>-----Original Message-----
>Sent: Tuesday, April 19, 2005 10:56 AM
>Subject: plot on condition
>
>hello
>my question about plotting a list of points but with some
>condition depends on
>the status of points in other list;
>pnts={{1,2},{5,4},{3,2},{2,6},{5,3}};
>cnd={7,3,5,8,3};
>the condition is: plot a point in list "pnts" in Blue if the
>corresponding
>element in list "cnd" is 3 else plot in Green
>regards
>
>



Define a function for the graphics directives

gd[3] = Sequence[PointSize[.025], Hue[2/3, 1, .7]];
gd[_] = Sequence[PointSize[.015], Hue[1/3, 1, .7]];

....and MapThread


Show[Graphics[{PointSize[.025],
MapThread[{gd[#2], Point[#1]} &, {pnts, cnd}]}]]


Of course, in case of only a single graphics directive you need no
Sequence, in case of none, {} is good as well as Sequence[], e.g.:

gd[3] = Sequence[PointSize[.025], Hue[2/3, 1, .7]];
gd[_] = {};

Show[Graphics[{PointSize[.015], Hue[1/3, 1, .7],
MapThread[{gd[#2], Point[#1]} &, {pnts, cnd}]}]]


--
Hartmut Wolf

DrBob

2005-04-20, 9:00 am

Needs["Graphics`Colors`"] (* not needed as of 5.1 *)

pnts = {{1, 2}, {5, 4}, {3, 2}, {2, 6}, {5, 3}};
cnd = {7, 3, 5, 8, 3};

coloredPoints = {If[#2 == 3,
Blue, Green], Point@#1} & @@@ Transpose@{pnts, cnd};
Show[Graphics@{AbsolutePointSize[7], coloredPoints}, Frame -> True];

or

coloredPoints = Transpose@{
cnd /. {3 -> Blue, x_Integer -> Green}, Point /@ pnts};
Show[Graphics@{AbsolutePointSize[7], coloredPoints}, Frame -> True]

Bobby


> hello
> my question about plotting a list of points but with some condition depends on
> the status of points in other list;
> pnts={{1,2},{5,4},{3,2},{2,6},{5,3}};
> cnd={7,3,5,8,3};
> the condition is: plot a point in list "pnts" in Blue if the corresponding
> element in list "cnd" is 3 else plot in Green
> regards
>
>
>
>




--
DrBob@bigfoot.com

Peter Pein

2005-04-20, 9:00 am

> hello
> my question about plotting a list of points but with some condition depends on
> the status of points in other list;
> pnts={{1,2},{5,4},{3,2},{2,6},{5,3}};
> cnd={7,3,5,8,3};
> the condition is: plot a point in list "pnts" in Blue if the corresponding
> element in list "cnd" is 3 else plot in Green
> regards
>

Show[Graphics[Prepend[
Transpose[{cnd/.{3->Blue,c_Integer->Green},Point/@pnts}],
PointSize[.02]]]]

will do it. Prepend[..,PointSize[.02]] is of course not necessary.
--
Peter Pein
Berlin

Bill Rowe

2005-04-20, 9:00 am


>hello my question about plotting a list of points but with some
>condition depends on the status of points in other list;
>pnts={{1,2},{5,4},{3,2},{2,6},{5,3}}; cnd={7,3,5,8,3}; the
>condition is: plot a point in list "pnts" in Blue if the
>corresponding element in list "cnd" is 3 else plot in Green regards



One way to do this in version 5.1 would be

Show[Block[{$DisplayFunction = Identity},
{ListPlot[Pick[pnts, (3 == #1 & ) /@ cnd], PlotStyle -> Blue],
ListPlot[Pick[pnts, (3 != #1 & ) /@ cnd], PlotStyle -> Green]}]];
--
To reply via email subtract one hundred and four

Mariusz Jankowski

2005-04-21, 9:00 am

Something like the following will work:

gr = If[#[[1]] == 3, {Red, #[[2]]}, {Blue, #[[2]]}] & /@ Thread[{cnd, Point
/@ pnts}]}

then

Show[Graphics[{PointSize[0.1], gr ]]


Mariusz




hello
my question about plotting a list of points but with some condition depends
on
the status of points in other list;
pnts={{1,2},{5,4},{3,2},{2,6},{5,3}};
cnd={7,3,5,8,3};
the condition is: plot a point in list "pnts" in Blue if the corresponding
element in list "cnd" is 3 else plot in Green
regards



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com