MathGroup Archive 2009

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

Search the Archive

Re: Mapping colours in DensityPlot

  • To: mathgroup at smc.vnet.net
  • Subject: [mg104185] Re: [mg104139] Mapping colours in DensityPlot
  • From: "David Park" <djmpark at comcast.net>
  • Date: Thu, 22 Oct 2009 02:19:14 -0400 (EDT)
  • References: <32739270.1256121620471.JavaMail.root@n11>

Most Mathematica color gradients go from 0 to 1 and not 0 to 255. And in
plots like DensityPlot Mathematica automatically scales the color parameter
to go from 0 to 1 over the plot. So you could use something like the
following:

A function that goes from 0 to 200:

f[x_, y_] := 200 Abs[Sin[x y]]

DensityPlot[f[x, y], {x, -\[Pi]/2, \[Pi]/2}, {y, -\[Pi]/2, \[Pi]/2},
 ColorFunction -> GrayLevel
 ]

But if you want to key the color to the actual value of the function you can
turn off the automatic scaling with ColorFunctionScaling and use
ColorFunction with Rescale to rescale 0 to 200 to 0 to 1.

DensityPlot[f[x, y], {x, -\[Pi]/2, \[Pi]/2}, {y, -\[Pi]/2, \[Pi]/2},
 ColorFunctionScaling -> False,
 ColorFunction -> Function[z, GrayLevel[Rescale[z, {0, 200}, {0, 1}]]]
 ]


David Park
djmpark at comcast.net
http://home.comcast.net/~djmpark/  



From: SeekUp [mailto:seek.up.girl at gmail.com] 

I am using the following command to do a DensityPlot in grayscale. The 
grayscale range is from 0-255, but I need to map my function to a grey-level

maximum of 200. How do I define a new GrayLevel with a max gray level of 
200? (Or alternately change the mapping so make the max level 200?)



DensityPlot[Mod[elementphase[x, y], 2 \[Pi]], {x, -0.008, 0.008}, 
{y, -0.006, 0.006}, PlotRange -> All, PlotPoints -> 120, ColorFunction -> 
GrayLevel, Frame -> False, ImageSize -> {{0, 800}, {0, 600}}, AspectRatio ->

600/800]



Any suggestions will be appreciated, although I'm a Mathematica newbie, so 
an example of what to do rather than a broad instruction would be 
invaluable.








  • Prev by Date: Re: Multi-Colored Filling in DateListPlot
  • Next by Date: Re: Mathematica7 doesn't copy/paste metafile in vector format
  • Previous by thread: Re: Mapping colours in DensityPlot
  • Next by thread: Re: Mapping colours in DensityPlot