i am pretty new in Mathematica but upt to now i am nearly done with my first higher plot. I just want to use the whole range of my 7 z-values linked to the 7 colors in my defined blend for #3 (z) (means -> class 7 shall be green,..., class 4 shall be orange,..., class 1 shall be red). So far the plot displays the given maximum value (6) in green and the given minimum (3) in Magenta but actually, in this case I want the plot to reach from class 3 (LightRed) to class 6 (LightGreen). Furthermore he will not display a Legend using the PlotLegend->Automatic option. How may i achieve both goals?

ListPlot3D[
{{4, 4, 3, 3, 3},
{4, 4, 4, 4, 3},
{5, 4, 3, 4, 4},
{5, 4, 4, 4, 4},
{5, 5, 4, 6, 5}},
Mesh -> {3}, BoxStyle -> Dashing[{0.01, 0.01}],
Axes -> True, AxesStyle -> Thickness[0.002],
DataRange -> {{10000, 50000}, {10000, 90000}, {0, 10}},
Ticks -> {
Table[i, {i, 10000, 50000, 10000}],
Table[i, {i, 10000, 90000, 20000}],
Table[i, {i, 0, 7, 1}]
},
TicksStyle -> 16,
PlotLabel -> "",
AxesLabel -> {
Framed["rpm [n]", FrameStyle -> None, FrameMargins -> 12],
Framed["U [V]", FrameStyle -> None, FrameMargins -> 12],
Framed[Rotate["Category", 90 Degree], FrameStyle -> None, FrameMargins -> 11]
},
LabelStyle -> Directive["Calibri", 18],
ImageSize -> Large,
ColorFunction->(Blend[{Magenta, Red, LightRed, Orange, Yellow, LightYellow, Green}, #3] &),
PlotRange -> {Automatic, Automatic, {1, 7}},
ViewPoint -> {1.1 Pi, -1.5 Pi, 1 Pi}
]

• I am not entirely sure what you are asking for, could you clarify it a bit? Also, there are several typos in your plotting code and I can only hazard a guess at what you intend. So, could you fix it and simplify it? Jan 29, 2016 at 14:56
• Thanks for the hint. I tried to edit the code but this one is copied directly and working fine in Mathematica. My aim is to use my defined color mix as fixed colors from 1-7 in the total z-range. Independend from the given values this color range should act like a template. If i now have z-values from 2-5 only the colors Red,LightRed,Orange and Yellow shall be used. If my data ranges from 1-7 all colors shall be used. Aditionally i would like to add a color-bar-legend which displays the colors with the corresponding z-values/categories/numbers(1-7). I hope I could make myself a little clearer. Jan 29, 2016 at 15:27
• That helps, at least enough that I can write up something coherent. Jan 29, 2016 at 15:31

By default, the plotting functions scale the dependent variables to $0$ to $1$, and the color functions, like Blend, use the same range. So, to have your custom color function respond to different ranges, you need to turn off scaling, e.g. add

ColorFunctionScaling -> False


to your plot. Of course, you then have to modify your color function to take the full range, e.g.

Blend[{{1, Magenta}, {2, Red}, {3, LightRed}, {4, Orange},
{5, Yellow}, {6, LightYellow}, {7, Green}}, #3]&


The addition of legend is a bit harder, due to some implementation issues, custom color functions are not passed to PlotLegends. But, we can fake it, e.g.

colors = {{1, Magenta}, {2, Red}, {3, LightRed}, {4, Orange},
{5, Yellow}, {6, LightYellow}, {7, Green}};


ColorFunction -> (Blend[colors, #3]&)