MathGroup Archive 2011

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: color-bar legend for the LisContourPlot

  • To: mathgroup at smc.vnet.net
  • Subject: [mg123613] Re: color-bar legend for the LisContourPlot
  • From: Mike H <mike.honeychurch at gmail.com>
  • Date: Tue, 13 Dec 2011 05:41:02 -0500 (EST)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • References: <201112091054.FAA03755@smc.vnet.net>

If you evaluate ColorData["Rainbow"] you will see that the function runs
from {0,1} therefore if ColorFunctionScaling is True in your contour plot,
by default it is I think, then you need to similarly scale your legend.
Like I said I don't normally use these sorts of plots but its seems to me
that ColorFunctionScaling should do this for you on the MatrixPlot. I
couldn't get it to work so had to manually scale things. I'm hoping that
someone else can explain what was going on with ColorFunctionScaling.

So in your matrix plot you want to plot Table[i,{0, div}]/div where div is
the number of divisions you want, i.e. the resolution of your legend. Or
alternatively Table[i,{0, 1, 1/div}]. Make some ticks:

ticks = Table[{i + 1, Rescale[i, {0, div}, {-2., 2.}]}, {i, 0, div}]

Here is an example with div

data = Table[{x = RandomReal[{-2, 2}], y = RandomReal[{-2, 2}],
    Sin[x y]}, {100}];

legendwidth = 30;
plotheights = 300;
div;

ticks = Table[{i + 1, Rescale[i, {0, 20}, {-2., 2.}]}, {i, 0, 20}];

Labeled[ListContourPlot[data, InterpolationOrder -> 3,
  ImageSize -> plotheights + 21, ImagePadding -> {{20, 1}, {20, 1}},
  ColorFunction -> "Rainbow"],
 MatrixPlot[Transpose@{Table[i, {i, 0, div}]/div},
  AspectRatio -> plotheights/legendwidth,
  FrameTicks -> {{None, ticks}, {None, None}},
  ImageSize -> {legendwidth + 21, plotheights + 2},
  ImagePadding -> {{1, 20}, {1, 1}}, ColorFunctionScaling -> False,
  ColorFunction -> "Rainbow"], {{Right, Top}}]


Mike
On Mon, Dec 12, 2011 at 9:59 PM, Karamiarokhloo, M.P. (Mehdipasha) <
M.P.Karamiarokhloo at uu.nl> wrote:

> Hi,
> The commands suggested by Jacopo and Armand, work well but if different
> data which include negative values are used
> then the problem appears that negative values do not come in the legend.At
> least I could not do it.
> Here is the command by Armand but I used a different input data.I got
> wrong color-bar...
>
> data = Table[{x = RandomReal[{-2, 2}], y = RandomReal[{-2, 2}],
>    Sin[x y]}, {100}];
>
> legendwidth = 30;
> plotheights = 300;
>
> Labeled[ListContourPlot[data, InterpolationOrder -> 3,
>  ImageSize -> plotheights + 21, ImagePadding -> {{20, 1}, {20, 1}},
>  ColorFunction -> "Rainbow"],
>  MatrixPlot[Transpose@{Table[i, {i, 1, -1, -0.2}]},
>  AspectRatio -> plotheights/legendwidth,
>  FrameTicks -> {{None, {-1, -0.5, 0, 0.5, 1}}, {None, None}},
>  ImageSize -> {legendwidth + 21, plotheights + 2},
>  ImagePadding -> {{1, 20}, {1, 1}},
>  ColorFunction -> "Rainbow"], {{Right, Top}}]
> ________________________________________
> From: Armand Tamzarian [mike.honeychurch at gmail.com]
> Sent: Sunday, December 11, 2011 9:47 AM
> To: mathgroup at smc.vnet.net
> Subject: Re: color-bar legend for the LisContourPlot
>
> On Dec 10, 11:36 pm, Jacopo Bertolotti <jacopo.bertolo... at gmail.com>
> wrote:
> > I encountered a very similar problem and I am also searching for a
> > solution that do not involve either ShowLegend or a third-part package.
> > The very best I came up with is something like
> > GraphicsRow[{ListContourPlot[RandomReal[30, {10, 10}],
> >     InterpolationOrder -> 3, ColorFunction -> "LakeColors"],
> >    MatrixPlot[Transpose@{Table[i, {i, 1, 30}]},
> >     FrameTicks -> {{None, {1, 10, 20, 30}}, {None, None}},
> >     ColorFunction -> "LakeColors"]}]
> > that is still far from ideal. Anyone with suggestions is welcomed.
> >
> > Jacopo
> >
> > On 12/09/2011 11:54 AM, Karamiarokhloo, M.P. (Mehdipasha) wrote:
> >
> >
> >
> >
> >
> >
> >
> > > Dear All,
> >
> > > I am using Mathematica 7 and have difficulties to plot the
> ListContourP=
> lot
> > > of ocean data with a neat color bar (legend).
> > > For example if I have a temperature field range between {-2,30}, and I
> =
> use
> > > the ColorFunction Rainbow,
> > > I cannot include a color-bar which has the same number of contours as
> t=
> he contourplot, and it does not show the related numbers for each
> color-sha=
> de.
> > > The ShowLegend function of Mathematica is very primitive.
> > > Has any body any suggestion?
> >
> > > Thanks you.
> > > P.Karami
>
> AFAIK Graphics grid renders fixed grid sizes so is not a good
> aesthetic choice if the plots you are combining have quite different
> sizes. You can do this a number of ways but I think Labeled makes this
> pretty easy once you make the plot and legend the same height (this is
> optional but for me it looks better):
>
> legendwidth=30;
> plotheights=300;
>
> Labeled[
>  ListContourPlot[RandomReal[30, {10, 10}],
>  InterpolationOrder -> 3,
>  ImageSize -> plotheights+21,
>  ImagePadding -> {{20, 1}, {20, 1}},
>  ColorFunction -> "LakeColors"],
>  MatrixPlot[Transpose@{Table[i, {i, 1, 30}]},
>  AspectRatio -> plotheights/legendwidth,
>  FrameTicks -> {{None, {1, 10, 20, 30}}, {None, None}},
>  ImageSize -> {legendwidth+21, plotheights+2},
>  ImagePadding -> {{1, 20}, {1, 1}},
>  ColorFunction -> "LakeColors"],
>  {{Right, Top}}]
>
> To understand what I am doing with image padding and aspect ratio see
> the current post "Precicely defining plot size ". You could control
> the spacing between the plot and the legend by adjusting the image
> padding on the plots.
>
> Mike
>
>


  • Prev by Date: "Need tutor" scam on newsgroup?
  • Next by Date: Seeking webMathematica consultant
  • Previous by thread: Re: color-bar legend for the LisContourPlot
  • Next by thread: Re: color-bar legend for the LisContourPlot