Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #2232

Re: A Request to Fix ShowLegend

From Peter Breitfeld <phbrf@t-online.de>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: A Request to Fix ShowLegend
Date 2011-05-09 10:21 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <iq8f6n$5vm$1@smc.vnet.net> (permalink)
References <iq3ari$fm1$1@smc.vnet.net>

Show all headers | View raw


"Kevin J. McCann" wrote:

> Sorry for the rant, but here it is:
>
> This has come up before in the ng, but today it is really irritating me; 
> so, I thought I would bring it up again. The issue is the putting of 
> legends on plots. In particular colorbars. Here is the example from the 
> ShowLegend documentation:
>
> ShowLegend[
>   Plot3D[Sin[x y], {x, 0, \[Pi]}, {y, 0, \[Pi]},
>    ColorFunction -> "Rainbow"], {ColorData["Rainbow"][1 - #1] &, 10,
>    " 1", "-1", LegendPosition -> {1.1, -.4}}]
>
> And, yes, it works just fine. However if you change the plotted function 
> to 2 Sin[x y], you get EXACTLY the same colorbar. This is nonsense. So, 
> in order to use ShowLegend, you have to do three things:
>
> 1) Do the Plot3D, or whatever the plot with its own ColorFunction;
> 2) As one of the arguments to ShowLegend, you define the Colorfunction, 
> but it is Reversed (how awkward is that?);
> 3) You have to know AND specify the limits of the colorbar, i.e. these 
> are just symbols and have absolutely nothing to do with the function 
> values that are plotted, and these are also reversed from the "normal" 
> way, i.e. "1","-1" instead of "-1","1", which is what I would have 
> guessed. As I said, you could put anything for these limits.
>
> This makes this part of the Legend suite useless or, at best, 
> extraordinarily cumbersome to use.
>
> I just wonder what the folks at Wolfram are thinking when they put out 
> the software this way with two really easy ways to mess it up, i.e. (2) 
> and (3) above.
>
> Now, I know that there is a package out there, ColorbarPlots, and it 
> works reasonably well and certainly makes my life easier; however it has 
> some limitations, in particular for the ColorFunction choices. Shouldn't 
> something like this be a part of Mathematica? Is there a good reason for 
> leaving ShowLegend the way it is? I am just wondering about the logic 
> here, and I am willing to admit that I might have missed something; 
> however, if there isn't a good reason, maybe it is time to fix it.
>
> Kevin
>

This might be a starter:

Options[plot3DWithLegend] = Union[Options[Plot3D], {cf -> "Rainbow"}];

plot3DWithLegend[f_, {x_, xmin_, xmax_}, {y_, ymin_, ymax_}, 
  opt : OptionsPattern[]] :=
Module[{min, max, cfOpt, plotOpt},
  cfOpt = OptionValue[cf];
  plotOpt = Evaluate[FilterRules[{opt}, Options[Plot3D]]];
  min = NMinValue[{f, xmin <= x <= xmax, ymin <= y <= ymax}, {x, y}];
  max = NMaxValue[{f, ymin <= y <= xmax, ymin <= y <= ymax}, {x, y}];
  ShowLegend[
   Plot3D[f, {x, xmin, xmax}, {y, ymin, ymax}, ColorFunction -> cfOpt,
     Evaluate@plotOpt],
   {ColorData[cfOpt][1 - #] &, 10, ToString@max, ToString@min,
    LegendPosition -> {1.1, -0.4}}
  ]
]

plot3DWithLegend[2 Sin[x y], {x, 0, \[Pi]}, {y, 0, \[Pi]},
 Background -> LightGreen, cf -> "Pastel"]

-- 
_________________________________________________________________
Peter Breitfeld, Bad Saulgau, Germany -- http://www.pBreitfeld.de

Back to comp.soft-sys.math.mathematica | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

A Request to Fix ShowLegend "Kevin J. McCann" <Kevin.McCann@umbc.edu> - 2011-05-07 11:36 +0000
  Re: A Request to Fix ShowLegend Peter Breitfeld <phbrf@t-online.de> - 2011-05-09 10:21 +0000
    Re: A Request to Fix ShowLegend "Kevin J. McCann" <Kevin.McCann@umbc.edu> - 2011-05-10 12:32 +0000

csiph-web