Re: Equivalent functionality to colorbar in Mathematica?
- To: mathgroup at smc.vnet.net
- Subject: [mg81804] Re: Equivalent functionality to colorbar in Mathematica?
- From: Will Robertson <wspr81 at gmail.com>
- Date: Wed, 3 Oct 2007 06:33:46 -0400 (EDT)
- References: <200709300744.DAA20164@smc.vnet.net><fdt3a6$roe$1@smc.vnet.net>
Hi,
That's a nice way to do it, David. Much better than what I was looking
at :)
For my own conveniece I've wrapped my attempt (but with a 2D density
plot instead) into a function (appended below).
My main concern with the thing is extracting the min/max values of the
colorbar: my method currently uses Sow[] on the expression inside
DensityPlot with an EvaluationMonitor. This seems very wasteful (since
the expression is being evaluated twice for each data point, right?)
-- is there a better way?
Many thanks,
Will
Options[ColorbarPlot] = {Colors -> "PigeonTones", CLabel -> "",
XLabel -> "", YLabel -> "", Title -> "", NContours -> 15,
Height -> 8*72/2.54};
ColorbarPlot[expr_, xr_, yr_, OptionsPattern[]] :=
Module[{contours},
rawPlot =
DensityPlot[expr, xr, yr,
EvaluationMonitor :> Sow[expr],
ImageSize -> {Automatic, OptionValue[Height]},
ColorFunction -> OptionValue[Colors],
FrameLabel -> {{OptionValue[YLabel], None}, {OptionValue[XLabel],
OptionValue[Title]}}] // Reap;
contours = rawPlot[[2, 1]];
Row[{rawPlot[[1]],
ContourPlot[
y, {x, 0, (Max[contours] - Min[contours])/
OptionValue[NContours]},
{y, Min[contours], Max[contours]},
Contours -> OptionValue[NContours],
ImageSize -> {Automatic, OptionValue[Height]},
ColorFunction -> OptionValue[Colors],
AspectRatio -> Automatic, PlotRange -> Full,
PlotRangePadding -> 0,
FrameLabel -> {{"", ""}, {"", OptionValue[CLabel]}},
FrameTicks -> {{All, None}, {{{0, ""}}, None}}]}]
]
ColorbarPlot[x^2 + y^2, {x, -10, 10}, {y, -10, 10}, XLabel -> "x",
YLabel -> "y", Title -> "Title", CLabel -> "Range"]