Re: contour-plot & ascii-art
- To: mathgroup at smc.vnet.net
- Subject: [mg23734] Re: contour-plot & ascii-art
- From: "Allan Hayes" <hay at haystack.demon.co.uk>
- Date: Mon, 5 Jun 2000 01:09:26 -0400 (EDT)
- References: <8gu7o7$hum@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Nicola:
The following may be of help.
<< Graphics`Colors`
<<Graphics`Legend`
Suppose that we wish to draw several contour plots with Contours ->
{z1,z2,..}and have the same colors correspond to the the same heights. The
following function will construct an appropriate color function
MakeColorFunction[cntrs_?OrderedQ, clrs_] /;
Length[clrs] == Length[cntrs] + 1 :=
Function @@ {Which @@
Flatten[{{# <= cntrs[[1]], clrs[[1]]},
Table[{cntrs[[i]] < # <= cntrs[[i + 1]], clrs[[i + 1]]}, {i, 1,
Length[cntrs] - 1}], {cntrs[[-1]] <= #, clrs[[-1]]}}
]}
For example, we get
MakeColorFunction[{z1, z2, z3}, {c1, c2, c3, c4}]
Which[#1 <= z1, c1, z1 < #1 <= z2, c2, z2 < #1 <= z3, c3,
z3 <= #1, c4] &
Let's make a contour plotplot.
cntrs = {-.9, -.6, -.3, 0, .3, .6, .9};
clrs = {Red, Blue, LightSeaGreen, YellowBrown, Khaki, Green, Purple,
Yellow};
cp = ContourPlot[(Cos[x] + Sin[y])/2, {x, 0, 2Pi}, {y, 0, 2Pi},
Contours -> cntrs,
ColorFunction -> (MakeColorFunction[cntrs, clrs]),
ColorFunctionScaling -> False];
Now the color key to the heights
key = Show[Graphics[{
Transpose[{clrs,
Rectangle[{0, #}, {1, # + 1}] & /@ Range[0, Length[cntrs]]}],
Table[
Text[NumberForm[cntrs[[n]], NumberSigns -> {"-", " "}], {1.3,
n}, {-1, 0}], {n, 1, Length[cntrs]}]
}], AspectRatio -> Automatic,
PlotRange -> {{0, 4}, {0, Length[cntrs] + 1}}];
Use Legend to place the key.
ShowLegend[cp,
{{{key, ""}}, LegendPosition -> {1.1, -.5}, LegendSize -> {.3, 1.2},
LegendSpacing -> 0, LegendShadow -> None,
LegendBorderSpace -> 0},
Frame -> True, FrameTicks -> False,
FrameStyle -> {Thickness[.02], Red}
];
--
Allan
---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565
"Nicola Attico" <attico at peg2.difi.unipi.it> wrote in message
news:8gu7o7$hum at smc.vnet.net...
> Someone can explain me how to create a
> shaded contour plot together with a bar where the
> various gray-levels have a numerical value
> specified (a sort of termometer).
> This is a very usual way of specifying the
> ``z-value'' associated with a gray-level.
> I'm sure Mathematica has this feature.
>
> /----------------\/-\
> | ||#| 50
> | ||#|
> | ||%| 40
> | contour ||%|
> | ||%| 20
> | ||.|
> | plot ||.| 10
> | ||.|
> | || | 0
> \----------------/\-/
>
>
> Is it clear? (sorry for the very bad ascii-art! :-)
>
> Nicola Attico
>
>