7 Added bug header.
source | link

Bug introduced in 9.0 or earlier and persisting through 11.0.1 or later


Consider this ContourPlot

ContourPlot[.05 - .005 (x^2 + y^2), {x, -12, 12}, {y, -12, 12}, 
 PlotRange -> {-2, 2},
 Contours -> 20,
 PlotLegends -> Automatic]

enter image description here

Clearly the color bar is wrong, assigning the region with the highest value to have the same color as the lowest value.

This problem goes away if you set the PlotRange-> All option, or if you set PlotRange-> {-2,x} where x is any number lower than 0.31 (e.g. 0.309999).

What is causing this behavior? Is it a bug?

Consider this ContourPlot

ContourPlot[.05 - .005 (x^2 + y^2), {x, -12, 12}, {y, -12, 12}, 
 PlotRange -> {-2, 2},
 Contours -> 20,
 PlotLegends -> Automatic]

enter image description here

Clearly the color bar is wrong, assigning the region with the highest value to have the same color as the lowest value.

This problem goes away if you set the PlotRange-> All option, or if you set PlotRange-> {-2,x} where x is any number lower than 0.31 (e.g. 0.309999).

What is causing this behavior? Is it a bug?

Bug introduced in 9.0 or earlier and persisting through 11.0.1 or later


Consider this ContourPlot

ContourPlot[.05 - .005 (x^2 + y^2), {x, -12, 12}, {y, -12, 12}, 
 PlotRange -> {-2, 2},
 Contours -> 20,
 PlotLegends -> Automatic]

enter image description here

Clearly the color bar is wrong, assigning the region with the highest value to have the same color as the lowest value.

This problem goes away if you set the PlotRange-> All option, or if you set PlotRange-> {-2,x} where x is any number lower than 0.31 (e.g. 0.309999).

What is causing this behavior? Is it a bug?

6 edited tags
| link
5 Edited OP's question to make it more clear, give the shortest working example
source | link

Erroneous color function for ContourPlot when the function has a related question about contourplotssmall positive region and the PlotRange is specified manually

So, I don't really even understandConsider this image - because the colors for the lowest range and the highest range are pretty much the same color! What kind of crazy color gradient is that? My understanding is that it should goe from one distinct color to another in the images, so one can identify the contour. Anyone have any ideas on even how this happens? Using this routine of some basic data to get the plots in the first place.ContourPlot

polyharmonicSpline[data_List, vars : {__}] /; 
MatrixQ[data, NumericQ] := 
Module[{bb, cofs, ls, lx, n, p, tx, xa, xap, wa, 
ws, \[CapitalPhi]}, {n, p} = Dimensions[data];
If[Length[vars] + 1 != p, Return[$Failed]];
wa = data[[All, -1]];
xa = Drop[data, None, -1];
tx = Transpose[xa]; xap = PadRight[xa, {n, p}, 1];
\[CapitalPhi] = 
Function[r, 
Piecewise[{{r Log[r^r], 0 < r < 1}, {r^2 Log[r], 1 < r}}, 0], 
Listable];
ls = LinearSolve[\[CapitalPhi][
 N[Function[point, Sqrt[Total[(point - tx)^2]]] /@ xa, 
  Precision[data]]]];
ws = ls[wa]; lx = ls[xap];
xap = Transpose[xap]; bb = LinearSolve[xap.lx, xapContourPlot[.ws];
(ws05 - lx.bb).\[CapitalPhi][EuclideanDistance[vars, #] & /@005 xa](x^2 + 
bb.Append[vars, 1]]

polyharmonicSpline[data_List, vars__] /; MatrixQ[data, NumericQ] := 
polyharmonicSpline[data, {vars}]

centeredXdataslice3 = AdjustOriginX[dataslice3];
AdjustOriginY[x_] := 
Partition[
Flatten@Transpose[{x[[All, 1]], CenterY /@ x [[All, 2]], 
  x[[All, 3]]}], 3];


centeredXYdataslice3 = AdjustOriginY[centeredXdataslice3];
dataSlice3Adj = NormalizeValues[centeredXYdataslice3]
f[x_, y_] := polyharmonicSpline[dataSlice3Adj, x, y];
slice3 = ContourPlot[f[x, y]y^2), {x, -12, 12}, {y, -12, 12}, 
ContourLabels -> Automatic,
Contours -> 20,
PlotLabel -> "Y = -4", PlotLegends -> BarLegend[Automatic, All], 
PlotRange -> {-2, 2}];

dataslice3 = {
{28, 18, 595.2}, {28, 22, 598.1}, {28, 26, 599.2}, {28, 30, 
599.4}, {28, 34, 599.0}, {28, 38, 597.7}, {28, 42, 594.6},
{32, 18, 597.6}, {32, 22, 600.5}, {32, 26, 601.8}, {32, 30, 
602.1}, {32, 34, 601.7}, {32, 38, 600.4}, {32, 42, 597.5},
{36, 18, 598.8}, {36, 22, 601.7}, {36, 26, 603.1}, {36, 30, 
603.3}, {36, 34, 603.0}, {36, 38, 601.7}, {36, 42, 599.0},
{40, 18, 599.0}, {40, 22, 601.8}, {40, 26, 603.3}, {40, 30, 
603.5}, {40, 34, 603.4}, {40, 38, 602.2}, {40, 42, 599.3},
{44, 18, 598.2}, {44, 22, 601.1}, {44, 26, 602.7}, {44, 30, 
603.0}, {44, 34, 603.0}, {44, 38, 601.8}, {44, 42, 599.1},
{48, 18, 596.6}, {48, 22, 599.6}, {48, 26, 601.0}, {48, 30, 
601.6}, {48, 34, 601.5}, {48, 38, 600.6}, {48, 42, 597.8},
{52, 18, 593.0}, {52, 22, 596.1}, {52, 26, 597.7},Contours {52,-> 3020, 
598.4}, {52, 34, 598.5}, {52, 38, 597.6}, {52,PlotLegends 42,-> 594.7}};Automatic]

Is producing very nice plotsenter image description here

Clearly the color bar is wrong, butassigning the scale looks really strange. The colors for a low range areregion with the highest value to have the same forcolor as the high rangelowest value. Dark blue

This problem goes away if you set the PlotRange-> All option, or if you set PlotRange-> {-2,x} where x is any number lower than 0 or.31 -1(e.52, what the heck? I don't get itg.

Thanks,

Eli 0.309999).

enter image description here What is causing this behavior? Is it a bug?

a related question about contourplots

So, I don't really even understand this image - because the colors for the lowest range and the highest range are pretty much the same color! What kind of crazy color gradient is that? My understanding is that it should goe from one distinct color to another in the images, so one can identify the contour. Anyone have any ideas on even how this happens? Using this routine of some basic data to get the plots in the first place.

polyharmonicSpline[data_List, vars : {__}] /; 
MatrixQ[data, NumericQ] := 
Module[{bb, cofs, ls, lx, n, p, tx, xa, xap, wa, 
ws, \[CapitalPhi]}, {n, p} = Dimensions[data];
If[Length[vars] + 1 != p, Return[$Failed]];
wa = data[[All, -1]];
xa = Drop[data, None, -1];
tx = Transpose[xa]; xap = PadRight[xa, {n, p}, 1];
\[CapitalPhi] = 
Function[r, 
Piecewise[{{r Log[r^r], 0 < r < 1}, {r^2 Log[r], 1 < r}}, 0], 
Listable];
ls = LinearSolve[\[CapitalPhi][
 N[Function[point, Sqrt[Total[(point - tx)^2]]] /@ xa, 
  Precision[data]]]];
ws = ls[wa]; lx = ls[xap];
xap = Transpose[xap]; bb = LinearSolve[xap.lx, xap.ws];
(ws - lx.bb).\[CapitalPhi][EuclideanDistance[vars, #] & /@ xa] + 
bb.Append[vars, 1]]

polyharmonicSpline[data_List, vars__] /; MatrixQ[data, NumericQ] := 
polyharmonicSpline[data, {vars}]

centeredXdataslice3 = AdjustOriginX[dataslice3];
AdjustOriginY[x_] := 
Partition[
Flatten@Transpose[{x[[All, 1]], CenterY /@ x [[All, 2]], 
  x[[All, 3]]}], 3];


centeredXYdataslice3 = AdjustOriginY[centeredXdataslice3];
dataSlice3Adj = NormalizeValues[centeredXYdataslice3]
f[x_, y_] := polyharmonicSpline[dataSlice3Adj, x, y];
slice3 = ContourPlot[f[x, y], {x, -12, 12}, {y, -12, 12}, 
ContourLabels -> Automatic,
Contours -> 20,
PlotLabel -> "Y = -4", PlotLegends -> BarLegend[Automatic, All], 
PlotRange -> {-2, 2}];

dataslice3 = {
{28, 18, 595.2}, {28, 22, 598.1}, {28, 26, 599.2}, {28, 30, 
599.4}, {28, 34, 599.0}, {28, 38, 597.7}, {28, 42, 594.6},
{32, 18, 597.6}, {32, 22, 600.5}, {32, 26, 601.8}, {32, 30, 
602.1}, {32, 34, 601.7}, {32, 38, 600.4}, {32, 42, 597.5},
{36, 18, 598.8}, {36, 22, 601.7}, {36, 26, 603.1}, {36, 30, 
603.3}, {36, 34, 603.0}, {36, 38, 601.7}, {36, 42, 599.0},
{40, 18, 599.0}, {40, 22, 601.8}, {40, 26, 603.3}, {40, 30, 
603.5}, {40, 34, 603.4}, {40, 38, 602.2}, {40, 42, 599.3},
{44, 18, 598.2}, {44, 22, 601.1}, {44, 26, 602.7}, {44, 30, 
603.0}, {44, 34, 603.0}, {44, 38, 601.8}, {44, 42, 599.1},
{48, 18, 596.6}, {48, 22, 599.6}, {48, 26, 601.0}, {48, 30, 
601.6}, {48, 34, 601.5}, {48, 38, 600.6}, {48, 42, 597.8},
{52, 18, 593.0}, {52, 22, 596.1}, {52, 26, 597.7}, {52, 30, 
598.4}, {52, 34, 598.5}, {52, 38, 597.6}, {52, 42, 594.7}};

Is producing very nice plots, but the scale looks really strange. The colors for a low range are the same for the high range. Dark blue is 0 or -1.52, what the heck? I don't get it.

Thanks,

Eli

enter image description here

Erroneous color function for ContourPlot when the function has a small positive region and the PlotRange is specified manually

Consider this ContourPlot

ContourPlot[.05 - .005 (x^2 + y^2), {x, -12, 12}, {y, -12, 12}, 
 PlotRange -> {-2, 2},
 Contours -> 20,
 PlotLegends -> Automatic]

enter image description here

Clearly the color bar is wrong, assigning the region with the highest value to have the same color as the lowest value.

This problem goes away if you set the PlotRange-> All option, or if you set PlotRange-> {-2,x} where x is any number lower than 0.31 (e.g. 0.309999).

What is causing this behavior? Is it a bug?

4 added 266 characters in body
source | link
3 added 266 characters in body
source | link
2 deleted 4 characters in body
source | link
1
source | link