RE: on ColorFunction and combined images?

• To: mathgroup at smc.vnet.net
• Subject: [mg47939] RE: [mg47930] on ColorFunction and combined images?
• From: "David Park" <djmp at earthlink.net>
• Date: Sat, 1 May 2004 02:43:04 -0400 (EDT)
• Sender: owner-wri-mathgroup at wolfram.com

```Sampo,

There is an error in the Mathematica conversion of DensityGraphics to
Graphics. It must perform this conversion to combine the two plots where one
of them is Graphics.

Consider...

Options[Raster]
{ColorFunction -> Automatic, ColorFunctionScaling -> True}

When converting to Graphics, Mathematica drops the ColorFunctionScaling
option.

Let's make a simple plot using Raster.

tab = Table[2x, {y, 0, 1, 0.2}, {x, 0, 1, 0.2}]
{{0, 0.4, 0.8, 1.2, 1.6, 2.},
{0, 0.4, 0.8, 1.2, 1.6, 2.},
{0, 0.4, 0.8, 1.2, 1.6, 2.},
{0, 0.4, 0.8, 1.2, 1.6, 2.},
{0, 0.4, 0.8, 1.2, 1.6, 2.},
{0, 0.4, 0.8, 1.2, 1.6, 2.}}

Show[Graphics[
{Raster[tab, {{0, 0}, {1, 1}},
ColorFunctionScaling -> False,
ColorFunction -> (Hue[#/2] &)]}],
AspectRatio -> Automatic,
Frame -> True];

Now make the same plot using DensityPlot.

plot1 =
DensityPlot[2x, {x, 0, 1}, {y, 0, 1},
Mesh -> False,
ColorFunctionScaling -> False,
ColorFunction -> (Hue[#/2] &),
PlotPoints -> 6];

Now, lets convert plot1 to Graphics and look at the first part.

First@Graphics@plot1

Raster[{{0., 0.4, 0.8, 1.2, 1.6,
2.}, {0., 0.4, 0.8, 1.2, 1.6,
2.}, {0., 0.4, 0.8, 1.2, 1.6,
2.}, {0., 0.4, 0.8, 1.2, 1.6,
2.}, {0., 0.4, 0.8, 1.2, 1.6,
2.}, {0., 0.4, 0.8, 1.2, 1.6,
2.}}, {{0., 0.}, {1., 1.}}, {0., 2.},
ColorFunction -> (Hue[#1/2] & )]

The ColorFunctionScaling option has been dropped and that is an error.

David Park

From: Sampo Smolander [mailto:sampo.smolander+newsnspam at helsinki.fi]
To: mathgroup at smc.vnet.net

Intro:

If I want to combine, say, a density field plot and an overlaid
curve on it, it is rather easy:

pic1 = DensityPlot[x^2, {x, 0, 1}, {y, 0, 1}, Mesh -> False]
pic2 = Plot[x^2, {x, 0, 1}]
Show[pic1, pic2]

My Case:

But say that I am plotting a densify field that that describes, just for
an example, some carbon dioxide concentrations for which a natural scale
(in the air outdoors) is something like 350...370 rather than 0...1.

I can tell DensityPlot to feed the raw concentration values
to the ColorFunction, and I can provide it my own ColorFunction:

mycf[x_] := RGBColor[0, 0, (x - 350)/20]
pic1 = DensityPlot[350 + 20*x^2, {x, 0, 1}, {y, 0, 1},
ColorFunctionScaling -> False, ColorFunction -> mycf, Mesh -> False]
pic2 = Plot[x^2, {x, 0, 1}]
Show[pic1, pic2]

The Problem:

There is no problem in drawing the pic1, but then when I try to
combine pic1 and pic2 with that Show, I get an error message:
"Argument in RGBColor[0, 0, -17.5] is not a real number between 0 and 1."

It apparently happens so that with Show, the pic1 is redrawn and (some
of?) the options that I gave in the original DensityPlot command are not
used anymore.

Is there a way around this problem?
How can I overlay other graphs with densityplots for which I have used my
own colorfunctions?

I think of the following: I could manually scale every function, that I
attempt to plot, to give out values only in the range 0...1. Then
I guess everything should work okay. But an easier way?

--
Sampo Smolander ............... http://www.cs.helsinki.fi/u/ssmoland/
Division of Atmospheric Sciences ............. University of Helsinki

```

• Prev by Date: Remove["Global`"] ??
• Next by Date: Re: strange problems with Random
• Previous by thread: Re: Remove["Global`"] ??
• Next by thread: RE: on ColorFunction and combined images?