Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Contour Plot / Plot Range / Contour Scaling

662 views
Skip to first unread message

m

unread,
Mar 1, 2010, 4:43:44 AM3/1/10
to
Hello All,

I apologize if this has been previously answered, but I have searched
through the posts for about an hour and have not found an answer to
this question.

Here is my scenario:

I have a family of contour plots and I have a range of values (z) that
spans the entire family (z from 0 to 1). Some plots will have data in
the full range and some will have only a subset of the range (say from
0 to 0.3). My goal is to to have a consistent contour plot coloring
scheme across all my plots (e.g. 0.5 is yellow on all my plots). It
seems like this should be accomplished through PlotRange, but that is
not the case.

Here is a bit of example code demonstrating my problem (with some
bogus function)

(* For Group *)
ShowLegend[
ContourPlot[0.3 x y^3, {x, 0, 1}, {y, 0, 1},
ColorFunction -> "ThermometerColors",
PlotLabel -> "Temp Dist through slice 1", FrameLabel -> Automatic,
PlotRange -> {0, 1}, Contours -> 19,
ContourLabels -> True], {ColorData["ThermometerColors"][1 - #1] &,
19, "1", "0", LegendPosition -> {0.8, -0.4}}]

So the max value of the function within the range is 0.3. And the
PlotLabel shows values ranging from 0 to 0.3 as expected. Yet the
shaded contours are displaying dark red in the upper right corner,
which is the value associated with 1. I would expect (and have in vain
been trying to get Mathemetica to do this) the upper right contour to
be light blue.

I am using Mathematica 7.0.1.0 (student edition if that matters)

Any help would be much appreciated! Thanks!!

Bob Hanlon

unread,
Mar 1, 2010, 8:06:25 AM3/1/10
to

Set the option ColorFunctionScaling to False in ContourPlot

Needs["PlotLegends`"]

ShowLegend[
ContourPlot[0.3 x y^3, {x, 0, 1}, {y, 0, 1},
ColorFunction -> "ThermometerColors",

ColorFunctionScaling -> False,


PlotLabel -> "Temp Dist through slice 1",
FrameLabel -> Automatic,
PlotRange -> {0, 1},
Contours -> 19,
ContourLabels -> True],
{ColorData["ThermometerColors"][1 - #1] &,
19, "1", "0",
LegendPosition -> {0.8, -0.4}}]


Bob Hanlon

---- m <mbar...@gmail.com> wrote:

=============

David Park

unread,
Mar 2, 2010, 3:34:46 AM3/2/10
to
In general you want to use ColorFunctionScaling -> False and then define
your ColorFunction based on the actual function values. To do that you have
to write it as a Function, or pure function, and use Rescale to map the
consistent z plot range for all plots to 0..1 used in the gradient colors.
So, without the legend, the plots statement might look like:

ContourPlot[0.3 x y^3, {x, 0, 1}, {y, 0, 1},

ColorFunctionScaling -> False,
ColorFunction -> (ColorData["ThermometerColors"][
Rescale[#, {0, 1}]] &), PlotLabel -> "Temp Dist through slice 1",


FrameLabel -> Automatic,
PlotRange -> {0, 1},
Contours -> 19,
ContourLabels -> True]

In your actual case you might have Rescale[#, {fmin,fmax}], the same for all
plots.
You might also want to specify specific contour values and make certain the
z PlotRange encompasses all of the contours you want in the plot.

You could get a much better legend by constructing it by hand. Just make
another ContourPlot z versus x, constant over x. You could get all the
contour lines on the legend with ticks and labels.


David Park
djm...@comcast.net
http://home.comcast.net/~djmpark/

0 new messages