1
$\begingroup$

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}
]
$\endgroup$
3
  • 1
    $\begingroup$ 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? $\endgroup$ – rcollyer Jan 29 '16 at 14:56
  • 1
    $\begingroup$ 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. $\endgroup$ – StephanJ Jan 29 '16 at 15:27
  • $\begingroup$ That helps, at least enough that I can write up something coherent. $\endgroup$ – rcollyer Jan 29 '16 at 15:31
2
$\begingroup$

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

enter image description here

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

then in your plotting function add both

ColorFunction -> (Blend[colors, #3]&)
PlotLegends -> BarLegend[{Blend[colors, #1]&, {1,7}}]

to get

enter image description here

$\endgroup$
3
  • $\begingroup$ Thank you very much. That is exactly the answer. Works very fine. But still a legend e.g . using PlotLegends -> Automatic is not plotted. Do you know why? $\endgroup$ – StephanJ Jan 29 '16 at 15:54
  • $\begingroup$ It has to do with the custom color function and the potential for non-linearities in it, and a way to easily handle the ramifications is not known. So, we have to fudge things a bit. Give me a second to add to my answer. $\endgroup$ – rcollyer Jan 29 '16 at 16:03
  • $\begingroup$ Great work, thanks a lot! Workarounds are pretty handy so it seems! $\endgroup$ – StephanJ Jan 29 '16 at 19:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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