1
$\begingroup$

I'm trying to graph a list of data with ListDensityPlot. My idea is to color negative values in red, zero in white and positive values in blue. I created a ColorFunction using Blend:

cf = Blend[{Blue,White,Red},#]&
ListDensityPlot[mydata, ColorFunction -> cf, PlotLegends -> Automatic]

Right now when I graph my data white is around -3. I could manually "center" my data, but I'm wondering whether there is a way to "center" the graph around white (zero) on the fly (by supplying options to ListDensityPlot or modifying cf).

$\endgroup$
  • 1
    $\begingroup$ Have you seen this? $\endgroup$ – J. M.'s technical difficulties Jul 17 '16 at 3:33
  • $\begingroup$ This helps, but I find LogisticSigmoid to be too sharp around 0 and with not much variation for Abs[x] > 4. I guess I could find a better function. $\endgroup$ – amrods Jul 17 '16 at 3:55
  • 1
    $\begingroup$ You can tune LogisticSigmoid's argument of course, to make the "s" more or less steep. $\endgroup$ – J. M.'s technical difficulties Jul 17 '16 at 5:31
  • 1
    $\begingroup$ True, actually that is more elegant. I ended up using cf = Blend[{Blue, White, Red}, LogisticSigmoid[#/3]] &. $\endgroup$ – amrods Jul 17 '16 at 5:44
  • 1
    $\begingroup$ …and of course, if LogisticSigmoid[] still doesn't suit you, there's ArcTan[], Tanh[], Erf[] $\endgroup$ – J. M.'s technical difficulties Jul 17 '16 at 6:07
2
$\begingroup$

One simple option:

ListDensityPlot[mydata, 
 ColorFunction -> (Blend[{{-10, Blue}, {0, White}, {5, Red}}, #] &), 
 ColorFunctionScaling -> False, PlotLegends -> Automatic]

enter image description here

A simple way to control blend:

minLegend = Min[mydata[[;; , -1]]];
maxLegend = Max[mydata[[;; , -1]]];
spdLegend = 2;

cf = Blend[{{minLegend , Blue}, {minLegend / spdLegend, LightBlue}, {0, White},
     {maxLegend / spdLegend, LightRed}, {maxLegend , Red}}, #] &;

ListDensityPlot[mydata, ColorFunction -> cf, 
 ColorFunctionScaling -> False, PlotLegends -> Automatic]

enter image description here

| improve this answer | |
$\endgroup$
  • $\begingroup$ Very nice! I guess I could also dynamically change the extremes with Min[data[[;;,-1]]] and Max[data[[;;,-1]]]. How do I change the "speed" of the blend? $\endgroup$ – amrods Jul 17 '16 at 3:59
  • 1
    $\begingroup$ @amrods cf = Blend[{{-10, Blue}, {-5, LightBlue}, {0, White}, {2.5, LightRed}, {5, Red}}, #] &; you could control when LightBlue and LightRed start based on the desired speed. $\endgroup$ – Young Jul 17 '16 at 4:12
  • $\begingroup$ I see, awesome. $\endgroup$ – amrods Jul 17 '16 at 4:13

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