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

Expressing values in the legend in terms of original data

1 view
Skip to first unread message

er

unread,
Oct 1, 2008, 7:12:42 AM10/1/08
to
Hi,

Considering

contourPlotFun=
ContourPlot[2 Sin[x y],{x,-\[Pi]/2,\[Pi]/2},{y,-\[Pi]/2,\[Pi]/2},
DisplayFunction\[Rule]Identity];

ShowLegend[
contourPlotFun,{GrayLevel[1-#]&,10," 1","-1",
LegendPosition\[Rule]{1.1,-.4}}];

The legend here is misleading, because the min and max values are -2
and 2, respectively, not -1 and 1. So how can I modify the input to
ShowLegend to reflect that?

Thanks!

Jens-Peer Kuska

unread,
Oct 1, 2008, 6:30:26 PM10/1/08
to
Hi,

the legend here is complete right, try
Plot3D[2 Sin[x y], {x, -\[Pi]/2, \[Pi]/2}, {y, -\[Pi]/2, \[Pi]/2}]

and so, simply remove the 2

Plot3D[Sin[x y], {x, -\[Pi]/2, \[Pi]/2}, {y, -\[Pi]/2, \[Pi]/2}]

and the problem is fixed.

Regards
Jens

er

unread,
Oct 1, 2008, 6:31:09 PM10/1/08
to

er

unread,
Oct 2, 2008, 4:36:38 AM10/2/08
to
On Oct 1, 6:30 pm, Jens-Peer Kuska <ku...@informatik.uni-leipzig.de>
wrote:

> Hi,
>
> the legend here is complete right, try
> Plot3D[2 Sin[x y], {x, -\[Pi]/2, \[Pi]/2}, {y, -\[Pi]/2, \[Pi]/2}]
>
> and so, simply remove the 2
>
> Plot3D[Sin[x y], {x, -\[Pi]/2, \[Pi]/2}, {y, -\[Pi]/2, \[Pi]/2}]
>
> and the problem is fixed.
>
> Regards
> Jens
>
> er wrote:
> > Hi,
>
> > Considering
>
> > contourPlotFun=
> > ContourPlot[2 Sin[x y],{x,-\[Pi]/2,\[Pi]/2},{y,-\[Pi]/2,\[Pi]/2=

},
> > DisplayFunction\[Rule]Identity];
>
> > ShowLegend[
> > contourPlotFun,{GrayLevel[1-#]&,10," 1","-1",
> > LegendPosition\[Rule]{1.1,-.4}}];
>
> > The legend here is misleading, because the min and max values are -2
> > and 2, respectively, not -1 and 1. So how can I modify the input to
> > ShowLegend to reflect that?
>
> > Thanks!

Thanks, but perhaps I did not make myself clear. I chose 2 Sin[x y]
precisely because the range is [-2,2]. I'm not trying to fit the data
to the legend, but rather the legend to the data.


sjoerd.c...@gmail.com

unread,
Oct 6, 2008, 4:14:16 AM10/6/08
to
In addition to my previous reply I should have taken the automatic
ranging of ContourPlot into account as it scales values to give a 0..1
range.

So, if you want to make sure the legend maps GrayLevels 0..1 to the
-2..2 range (in case the ends of this range are not within the plot
region) you have to adjust the scaling of ContourPlot accordingly:

contourPlotFun =
ContourPlot[
2 Sin[x y], {x, -\[Pi]/2, \[Pi]/2}, {y, -\[Pi]/2, \[Pi]/2},
ColorFunctionScaling -> False,
ColorFunction -> (GrayLevel[1 - ((# + 2)/4)] &)];

ShowLegend[contourPlotFun, {GrayLevel[1 - #] &, 10, " 2", "-2",
LegendPosition -> {1.1, -.4}, LegendShadow -> None}]


Cheers -- Sjoerd

sjoerd.c...@gmail.com

unread,
Oct 6, 2008, 4:32:04 AM10/6/08
to
Er,

In my version of Mathematica (6.03 WinXP) the ContourPlot is in color
by default. It doesn't make sense to add a grayscale legend. So either
you color the legend or you add a greyscale ColorFunction to the
ContourPlot:

contourPlotFun =
ContourPlot[
2 Sin[x y], {x, -\[Pi]/2, \[Pi]/2}, {y, -\[Pi]/2, \[Pi]/2},
ColorFunction -> (GrayLevel[1 - #] &)];

ShowLegend[contourPlotFun, {GrayLevel[1 - #] &, 10, " 2", "-2",

LegendPosition -> {1.1, -.4}}]

The legend doesn't adapt to the range of your plot. You have to
provide the range yourself. In the expression above I put in 2 and -2
and that does the trick.

Cheers,

Sjoerd

On Oct 1, 1:12 pm, er <erwann.rog...@gmail.com> wrote:

0 new messages