MathGroup Archive 1998

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Help coloring plot



Paul Bublitz wrote:
> 
> I have a class assignment (hi Ken) to create a graph consisting of data
> from a table plotted blue, a single point plotted in red,  and lines
> connecting the single point to the table plotted in  greenish yellow.
> I can plot each (point, table, and line) separately in the specified
> colors.  When I combine the individual plots into a module as shown
> below, I only get a single color.  How can I plot this  in three
> colors?
> 
> plotpoly[sides_,point_]:=
>         Module[{p1,p2,p3,data},
> data=Table[{Cos[I 2.\[Pi]/sides],Sin[I 2.\[Pi]/sides]},{I,sides}];
> 
> p1=ListPlot[data,PlotStyle->PointSize[.03],DefaultColor-
> >RGBColor[0,0,1],DisplayFunction->Identity];
> 
> p2=Graphics[{PointSize[.03],Point[point]},DefaultColor-
> >RGBColor[1,0,0]];
> 
> p3=Graphics[Table[Line[{point,data[[I]]}],{I,sides}],DefaultColor-
> >RGBColor[.8,1,0];
> 
> Show[{p1,p2,p3},Axes->False,AspectRatio->Automatic,
>       DisplayFunction->$DisplayFunction]
> 
> -------------
> Paul Bublitz
> tpa@radix.net


Paul, 
1) you need to put the color directive in a list in with the objects to
be colored, and preceding them.
2) there don't seem to be any lines in your code 3) it would be better
not to use list plot.

For example

plotpoly[sides_,point_]:=
        Module[{p1,p2,p3,data},
data=Table[{Cos[i 2.\[Pi]/sides],Sin[i 2.\[Pi]/sides]},{i,sides}];
p3=Graphics[{RGBColor[.8,1,0],Line[{point,#}]&/@data}];

p1=Graphics[{PointSize[.03],RGBColor[0,0,1],Point[#]&/@data}];

p2=Graphics[{PointSize[.03],RGBColor[1,0,0],Point[point]}];
		
Show[{p3,p1,p2},AspectRatio->Automatic]
	]
 
Note that the lines must be come first if they are to be behind the
points.

-- 
Allan Hayes
Training and Consulting
Leicester, UK
hay@haystack.demon.co.uk
http://www.haystack.demon.co.uk
voice: +44 (0)116 271 4198
fax: +44 (0)116 271 8642




  • Prev by Date: RE: Simple question
  • Next by Date: Re:
  • Prev by thread: Re: Help coloring plot
  • Next by thread: Help with Discrete Math Problems