Re: Re: Change colors in contour plot and including a legend?
- To: mathgroup at smc.vnet.net
- Subject: [mg82087] Re: [mg82045] Re: Change colors in contour plot and including a legend?
- From: Syd Geraghty <sydgeraghty at mac.com>
- Date: Fri, 12 Oct 2007 02:46:48 -0400 (EDT)
- References: <fefina$jol$1@smc.vnet.net> <200710100829.EAA26827@smc.vnet.net>
Will, Thanks very much for the contribution of an excellent package which adds to the prior contributions of David Park, & Bobby (DrMajorBob) answering Sean Incali's original question. I have just received the latest book of Edward Tufte titled "Beautiful Evidence" and I was struck by how nicely the addition of the scaled legend bar adds significant value to the original function output and meets Tufte's concept of superior visual evidence and explanation. I pass along the quote below hoping it will be of general interest to the group. In his first chapter "Mapped Pictures: Images as Evidence and Explanation" Tufte writes:- "Explanatory, journalistic, and scientific images should nearly always be mapped, contextualized, and placed on the universal grid. Mapped pictures combine representational images with scales, diagrams, overlays, numbers, words, images. Good mappings of realistic images have been produced throughout the long history of visual displays, but not often enough. An explanatory image is an explanatory image because it is a mapped image. Sensibly mapped pictures nearly always outperform purely pictorial representations for presenting, explaining, and documenting evidence." Cheers ... Syd Syd Geraghty B.Sc., M.Sc. sydgeraghty at mac.com San Jose, CA On Oct 10, 2007, at 1:29 AM, Will Robertson wrote: > On Oct 9, 6:47 pm, sean_incali <sean_inc... at yahoo.com> wrote: >> Can you change the output of the ContourPlot from gray levels to >> colors? And then have a legend that breaks down the levels into say >> 10 or whatever number of bins and denote what the values are? > > I've attached a package that might help. > I wrote it the other day following help from this very list, and I'm > sure it can be improved. Feedback welcome. > > Use it like this: > > ColorbarPlot[#1^2 + #2^2 &, {-10, 10}, {-5, 5}] > > By default it creates a density plot, but that can be changed: > > ColorbarPlot[#1^2 + #2^2 &, {-10, 10}, {-5, 5}, > PlotType -> ContourPlot, > Colors -> "DarkBands", > XLabel -> "x", > YLabel -> "y", > Title -> "Title", > CLabel -> "Range", > Height -> 300] > > Hope this helps, > Will > > ************* > > ColorbarPlot v0.1 > 2007 Oct 08 > > ColorbarPlot is a function to plot either a ContourPlot or a > DensityPlot with an attached colorbar to indicate the ranges of the > function that is being plotted. The syntax is not exactly the same as > for ContourPlot or DensityPlot. > > Please see the code below (or ?ColorbarPlot) for further details. An > example file should be distributed with this package to demonstrate > its use. > > This package has been written with and for Mathematica 6.0.0. > I doubt that it will work in previous versions of Mathematica. > Who knows if it will work in the future. > > Please send comments and suggestions to wspr 81 at gmail dot com. > > Copyright 2007 > Will Robertson > > This package consists of the files ColorbarPlot.m and ColorbarPlot- > examples.nb. It may be freely distributed and modified under the terms > & conditions of the Apache License, v2.0: <http://www.apache.org/ > licenses/LICENSE-2.0> > > BeginPackage["ColorbarPlot`"]; > > ColorbarPlot::usage = > "ColorbarPlot[F[x,y],{Xmin,Xmax},{Ymin,Ymax},<options>]: > Creates a DensityPlot or a ContourPlot with an attached > colorbar to denote the range of the function F[x,y]. > > Options (defaults shown) are: > PlotType -> DensityPlot (or ContourPlot, or ...?) > Colors -> \"LakeColors\" (or \"PidgeonTones\" or ...) > XLabel -> \"\" (label below the plot frame) > YLabel -> \"\" (label left of the plot frame) > Title -> None (label above the plot from) > CLabel -> None (label above the colorbar) > Height -> 8*72/2.54 (height of the plot; 8cm default) > > Regular options to the plot function will also be > passed through. (Therefore, XLabel and YLabel, etc. > can be overriden with a regular FrameLabel option.)"; > > Begin["`Private`"] > > Options[ColorbarPlot]={ > Colors -> "LakeColors", > PlotType -> DensityPlot, > XLabel -> "", > YLabel -> "", > CLabel -> None, > Title -> None, > Height -> 8*72/2.54 > }; > > ColorbarPlot[ > function_,{___,x1_,x2_},{___,y1_,y2_}, > opts:OptionsPattern[]] := > Module[ > (* local variables *) > {contours, > monitor, > max = -Infinity, > min = Infinity, > Opt,x,y}, > > (* Option processing > (filter out options for the plot itself) *) > Opt[x_] := > OptionValue[ColorbarPlot, > FilterRules[{opts},Options[ColorbarPlot]], > x]; > > (* Define a function from the input that records the > maxima and minima of the function as it is evaluated. > This information is then used in the colorbar. *) > monitor[x_?NumericQ,y_?NumericQ] := > Module[{val=function[x,y]}, > min=Min[min,val]; > max=Max[max,val]; > val]; > > (* Draw the plot and colorbar next to each other *) > Row[{ > (* Here's the plot: *) > Opt[PlotType][ > monitor[x,y],{x,x1,x2},{y,y1,y2}, > Evaluate[FilterRules[{opts}, > Options[Opt[PlotType]]]], > ImageSize -> {Automatic,Opt[Height]}, > ColorFunction -> Opt[Colors], > FrameLabel -> {{Opt[YLabel],None}, > {Opt[XLabel],Opt[Title]}}], > (* And the colourbar: *) > Opt[PlotType][ > y,{x,0,(max-min)/10},{y,min,max}, > ImageSize -> {Automatic,Opt[Height]}, > ColorFunction -> Opt[Colors], > PlotRange -> Full, > AspectRatio -> Automatic, > PlotRangePadding -> 0, > FrameLabel -> {{"",""},{"",Opt[CLabel]}}, > (* the empty frame tick here is > to align the colorbar with the plot: *) > FrameTicks -> {{All,None},{{{0,""}},None}}] > }]] > > End[]; > EndPackage[]; > >
- References:
- Re: Change colors in contour plot and including a legend?
- From: Will Robertson <wspr81@gmail.com>
- Re: Change colors in contour plot and including a legend?