# Problems with legends for list density plots [duplicate]

When plotting list density plot in Mathematica 8.0, the following problems arise:

1. PlotLegends doesn't work, so I use ShowLegend which withdraws the second problem:

2. the difficulties in matching the density colors with corresponding label colors in legend, i.e. it does not display automatically. Also legend does not display max and min density values, nor the intermediate ticks.

Here I outline my code:

d = ListDensityPlot[data, PlotRange -> All,
ColorFunction -> ColorData["FallColors"], ClippingStyle -> Automatic];

max_d = Max[data[[All,3]]];
min_d = Min[data[[All,3]]];

ShowLegend[d, {ColorData["FallColors"][1 - #] &, 10, "max_d", "min_d",
LegendShadow -> None, LegendPosition -> {1.5, -0.7} }]


where data is a table containing elements of the form $\{x_i, y_i ,f(x_i, y_i)\}$, in particular

data = {
{0, 0, 1}, {0, 1, 1}, {0, 2, 1}, {0, 3, 1}, {0, 4, 1},
{1, 0, Cos}, {1, 1, Cos^2}, {1, 2, Cos Cos}, {1, 3, Cos Cos},
{1, 4, Cos Cos}, {2, 0, Cos}, {2, 1, Cos^2}, {2, 2, Cos Cos},
{2, 3, Cos Cos}, {2, 4, Cos Cos}, {3, 0, Cos}, {3, 1, Cos^2},
{3, 2, Cos Cos}, {3, 3, Cos Cos}, {3, 4, Cos Cos}
}


However, I would like to have more gradual display (not only 10 different shades) in legend, and automatic evaluation of min and max.

• Your question will get more attention if you provide a sample dataset for data in your post. Also, note that PlotLegends was introduced in version 9.0 so is not available in 8.0 – Edmund Sep 8 '16 at 20:23

## 1 Answer

\$Version

(*  "8.0 for Mac OS X x86 (64-bit) (July 22, 2012)"  *)

data = {{0, 0, 1}, {0, 1, 1}, {0, 2, 1}, {0, 3, 1}, {0, 4, 1}, {1, 0,
Cos}, {1, 1, Cos^2}, {1, 2, Cos Cos}, {1, 3,
Cos Cos}, {1, 4, Cos Cos}, {2, 0, Cos}, {2, 1,
Cos^2}, {2, 2, Cos Cos}, {2, 3, Cos Cos}, {2, 4,
Cos Cos}, {3, 0, Cos}, {3, 1, Cos^2}, {3, 2,
Cos Cos}, {3, 3, Cos Cos}, {3, 4, Cos Cos}};

d = ListDensityPlot[data, PlotRange -> All,
ColorFunction -> ColorData["FallColors"], ClippingStyle -> Automatic];


Note that you cannot use an underscore in a variable name

maxD = Max[data[[All, 3]]];
minD = Min[data[[All, 3]]];

Needs["PlotLegends"]

ShowLegend[d, {
ColorData["FallColors"][1 - #] &,
25, ToString[maxD], ToString[minD],
LegendShadow -> None,
LegendSize -> {.4, 1.5},
LegendPosition -> {1.1, -0.7}}]
` 