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

Plotting ListDensityPlot with Custom Color Scheme

1,066 views
Skip to first unread message

Buz Barstow

unread,
Sep 12, 2008, 5:27:33 AM9/12/08
to
Dear All,

I'm trying to plot out a color map of a matrix with a custom color
scheme, and add a legend to it.

The maximum value in the matrix is approximately 1.7, and the lowest
value is -2.7. Most of the values lie in the range -0.5 to +0.5.

When Mathematica 6.0 produces a ListDensityPlot of this matrix, it
color codes most of the plot, but it leaves large areas with
"overflow" colors - some of the plot is displayed as white, not on the
color map.

I'd like to be able to rescale the color function so that it spans the
range -2.7 to 1.7, and produce a legend for the plot that accurately
reflects this.

Thanks! and all the best,

--Buz

Bill Rowe

unread,
Sep 13, 2008, 5:56:37 AM9/13/08
to

So, use the built-in function Rescale. For example,

ColorFunction->(Hue@Rescale[#,{-2.7,1.7}]&)

will eliminate the white areas. But note, this choice maps both
minimum and maximum values to the same color. So, it is probably
not one you want. Better might be

ColorFunction->(ColorData["TemperatureMap"][Rescale[#,{-2.7,1.7}]]&)

Szabolcs Horvát

unread,
Sep 13, 2008, 5:57:41 AM9/13/08
to

MatrixPlot or ArrayPlot may be more suitable for this than
ListDensityPlot (try them).

With ListDensityPlot, use the option PlotRange -> All, or PlotRange ->
{-2.7, 1.7} to set the range of values to be included in the plot.

The ColorFunction and ColorFunctionScaling options may also be useful.

The legend can be added with the Plot Legends package,

http://reference.wolfram.com/mathematica/PlotLegends/tutorial/PlotLegends.html

Unfortunately that package can be a little problematic to use sometimes,
so you may want to try this alternative:

http://www.walkingrandomly.com/?p=24

michael.p...@googlemail.com

unread,
Oct 4, 2008, 6:18:14 AM10/4/08
to
Hi All,

There is an update to the package that Szabolcs mentioned - you can
find it here:

http://www.walkingrandomly.com/?p=116

On Sep 13, 10:57 am, Szabolcs Horv=E1t <szhor...@gmail.com> wrote:
> Buz Barstow wrote:
> > Dear All,
>
> > I'm trying to plot out a color map of a matrix with a custom color
> > scheme, and add a legend to it.
>

> > The maximum value in the matrix is approximately 1.7, and the lowest =



> > value is -2.7. Most of the values lie in the range -0.5 to +0.5.
>
> > When Mathematica 6.0 produces a ListDensityPlot of this matrix, it
> > color codes most of the plot, but it leaves large areas with

> > "overflow" colors - some of the plot is displayed as white, not on the =

> > color map.
>
> > I'd like to be able to rescale the color function so that it spans the =

> > range -2.7 to 1.7, and produce a legend for the plot that accurately =



> > reflects this.
>
> MatrixPlot or ArrayPlot may be more suitable for this than
> ListDensityPlot (try them).

> With ListDensityPlot, use the option PlotRange -> All, or PlotRange ->
> {-2.7, 1.7} to set the range of values to be included in the plot.
>
> The ColorFunction and ColorFunctionScaling options may also be useful.
>
> The legend can be added with the Plot Legends package,
>

> http://reference.wolfram.com/mathematica/PlotLegends/tutorial/PlotLeg...

michael.p...@googlemail.com

unread,
Oct 5, 2008, 2:24:28 AM10/5/08
to
Hi All,

There is an update to the package that Szabolcs mentioned - you can
find it here:

http://www.walkingrandomly.com/?p=116

On Sep 13, 10:57 am, Szabolcs Horv=E1t <szhor...@gmail.com> wrote:

> Buz Barstow wrote:
> > Dear All,
>
> > I'm trying to plot out a color map of a matrix with a custom color
> > scheme, and add a legend to it.
>

> > The maximum value in the matrix is approximately 1.7, and the lowest =



> > value is -2.7. Most of the values lie in the range -0.5 to +0.5.
>
> > When Mathematica 6.0 produces a ListDensityPlot of this matrix, it
> > color codes most of the plot, but it leaves large areas with

> > "overflow" colors - some of the plot is displayed as white, not on the =

> > color map.
>
> > I'd like to be able to rescale the color function so that it spans the =

> > range -2.7 to 1.7, and produce a legend for the plot that accurately =



> > reflects this.
>
> MatrixPlot or ArrayPlot may be more suitable for this than
> ListDensityPlot (try them).

> With ListDensityPlot, use the option PlotRange -> All, or PlotRange ->
> {-2.7, 1.7} to set the range of values to be included in the plot.
>
> The ColorFunction and ColorFunctionScaling options may also be useful.
>
> The legend can be added with the Plot Legends package,
>

> http://reference.wolfram.com/mathematica/PlotLegends/tutorial/PlotLeg...

michael.p...@googlemail.com

unread,
Oct 5, 2008, 5:39:16 AM10/5/08
to
Hi All,

There is an update to the package that Szabolcs mentioned - you can
find it here:

http://www.walkingrandomly.com/?p=116

On Sep 13, 10:57 am, Szabolcs Horv=E1t <szhor...@gmail.com> wrote:

> Buz Barstow wrote:
> > Dear All,
>
> > I'm trying to plot out a color map of a matrix with a custom color
> > scheme, and add a legend to it.
>

> > The maximum value in the matrix is approximately 1.7, and the lowest =



> > value is -2.7. Most of the values lie in the range -0.5 to +0.5.
>
> > When Mathematica 6.0 produces a ListDensityPlot of this matrix, it
> > color codes most of the plot, but it leaves large areas with

> > "overflow" colors - some of the plot is displayed as white, not on the =

> > color map.
>
> > I'd like to be able to rescale the color function so that it spans the =

> > range -2.7 to 1.7, and produce a legend for the plot that accurately =



> > reflects this.
>
> MatrixPlot or ArrayPlot may be more suitable for this than
> ListDensityPlot (try them).

> With ListDensityPlot, use the option PlotRange -> All, or PlotRange ->
> {-2.7, 1.7} to set the range of values to be included in the plot.
>
> The ColorFunction and ColorFunctionScaling options may also be useful.
>
> The legend can be added with the Plot Legends package,
>

> http://reference.wolfram.com/mathematica/PlotLegends/tutorial/PlotLeg...

0 new messages