0
$\begingroup$

This question already has an answer here:

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, 1, Cos[1]^2}, {1, 2, Cos[1] Cos[2]}, {1, 3, Cos[1] Cos[3]}, 
  {1, 4, Cos[1] Cos[4]}, {2, 0, Cos[2]}, {2, 1, Cos[2]^2}, {2, 2, Cos[2] Cos[4]}, 
  {2, 3, Cos[2] Cos[6]}, {2, 4, Cos[2] Cos[8]}, {3, 0, Cos[3]}, {3, 1, Cos[3]^2}, 
  {3, 2, Cos[3] Cos[6]}, {3, 3, Cos[3] Cos[9]}, {3, 4, Cos[3] Cos[12]}
}

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

$\endgroup$

marked as duplicate by Jens plotting Jan 10 '17 at 18:01

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    $\begingroup$ 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 $\endgroup$ – Edmund Sep 8 '16 at 20:23
0
$\begingroup$
$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, 1, Cos[1]^2}, {1, 2, Cos[1] Cos[2]}, {1, 3, 
    Cos[1] Cos[3]}, {1, 4, Cos[1] Cos[4]}, {2, 0, Cos[2]}, {2, 1, 
    Cos[2]^2}, {2, 2, Cos[2] Cos[4]}, {2, 3, Cos[2] Cos[6]}, {2, 4, 
    Cos[2] Cos[8]}, {3, 0, Cos[3]}, {3, 1, Cos[3]^2}, {3, 2, 
    Cos[3] Cos[6]}, {3, 3, Cos[3] Cos[9]}, {3, 4, Cos[3] Cos[12]}};

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}}]

enter image description here

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.