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 - 01 Oct 2008 23:30 GMT
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
> Hi,
>
[quoted text clipped - 13 lines]
>
> Thanks!
er - 02 Oct 2008 09:36 GMT
On Oct 1, 6:30 pm, Jens-Peer Kuska <ku...@informatik.uni-leipzig.de>
wrote:
> Hi,
>
[quoted text clipped - 16 lines]
> > contourPlotFun=
> > ContourPlot[2 Sin[x y],{x,-\[Pi]/2,\[Pi]/2},{y,-\[Pi]/2,\[Pi]/2=
},
> > DisplayFunction\[Rule]Identity];
>
[quoted text clipped - 7 lines]
>
> > 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.devries@gmail.com - 06 Oct 2008 09:14 GMT
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
> Hi,
>
[quoted text clipped - 13 lines]
>
> Thanks!
sjoerd.c.devries@gmail.com - 06 Oct 2008 09:32 GMT
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
> Hi,
>
[quoted text clipped - 3 lines]
> 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",
[quoted text clipped - 5 lines]
>
> Thanks!