MathGroup Archive 1994

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

Search the Archive

Re:Coloring 2DPlot with different colors


Jian-hua writes:
> Does any one knows how to make on 2DPlot with different colors? For 
> example, I'd like to use two different color to emphasize decreasing or 
> increasing of a function or the positive and negative values of a > function.


The basic idea is to get at the Line object in the  -Graphics- output and
change it in the way that you want..
You can see this code by using InputForm.
I have left the code pretty rough in the interests of explicitness.
You could also colour according to slope.

(Plot[Sin[x],{x,0,2Pi}, DisplayFunction->Identity]
	/.Line[p_]
		:> Line/@Partition[p,2,1]
	/.ln:Line[{{x1_,y1_},{x2_,y2_}}] 
		:> {If[y1<=y2, Hue[0],Hue[2/3]],ln}
);
Show[%, DisplayFunction->$DisplayFunction]
	

(Plot[Sin[x],{x,0,2Pi}, DisplayFunction->Identity]
	/.Line[p_]
		:> Line/@Partition[p,2,1]
	/.Line[{{x1_,y1_},{x2_,y2_}}]/;y1 y2 <0 
		:> {Line[{{x1,y1},{x2,0}}], Line[{{x1,0},{x2,y2}}]} 
	/.ln:Line[{{x1_,y1_},{x2_,y2_}}] 
		:> {If[Max[y1,y2] <=0,Hue[0],Hue[2/3]],ln}
);
Show[%, DisplayFunction->$DisplayFunction]



Allan Hayes,
hay at le.ac.uk






  • Prev by Date: Re: Coloring 2DPlot with different colors
  • Next by Date: re: From Mathematica to Gnuplot
  • Previous by thread: Re: Coloring 2DPlot with different colors
  • Next by thread: re: Coloring 2DPlot with different colors