I am seeking assistance in creating a contour plot that displays both positive and negative contour values. I want the contour lines with positive values to be colored red, and those with negative values to be blue, as illustrated in the provided figure. enter image description here Furthermore, I have utilized the code provided by the author @azerbajdzan, which works well with their test data. How to construct a contour plot so that positive contour lines are colored red and negative contour lines are colored blue However, I am encountering issues when applying it to my data, as it does not visualize the contour lines with negative values correctly, resulting in gaps. I am also unable to adjust the number of contour lines for positive and negative values. I would greatly appreciate any guidance on how to modify the code to suit my data and set different levels for the contour lines for positive and negative values.

mm = MinMax@data[[All, 6]]
d = 0.001;
cont = Table[{Rescale[k, {0, 1}, mm], 
    Blend[{Blue, White, Red}, k]}, {k, 0, 1, d/(mm[[2]] - mm[[1]])}];
ListContourPlot[data[[All, {4, 5, 6}]], ContourShading -> None, 
 Contours -> cont]

enter image description here

Data https://dropmefiles.com/oZrng

  • $\begingroup$ ContourPlot[Sin[ x y], {x, -3, 3}, {y, -3, 3}, Contours -> 5, ContourStyle -> {Red, Red, Red, Green, Green, Green}] $\endgroup$ Commented Apr 20 at 15:52
  • $\begingroup$ You are using 4,5,6 parts of data, are parts 1,2,3 any relevant? $\endgroup$ Commented Apr 20 at 17:24
  • $\begingroup$ Columns 1,2,3 correspond to the original Cartesian coordinates X,Y,Z. Columns 4,5,6 correspond to the X,Y plane coordinates on the graph and the function value, respectively. $\endgroup$
    – user98502
    Commented Apr 20 at 17:54

1 Answer 1


The resulting image strongly depends on the chosen contours values.

I think in the OP image some king of exponential distribution of contours were chosen.

data = ImageData[Import["https://i.sstatic.net/x8ARkRiI.png"], "Byte"] // Flatten // 
    FromCharacterCode // Uncompress;

cont = If[# < 0, {#, ColorData[97, 1]}, {#, ColorData[97, 4]}] & /@ 
     Join[#, -#] &@N[Table[E^n, {n, -7, 14}]];

ListContourPlot[data, ContourShading -> None, Contours -> cont, 
 PlotRange -> All]

enter image description here

With Table[E^n, {n, -7, 14, 1/2}].

enter image description here

data stored in image:

  • 1
    $\begingroup$ Your solution is great!!! I greatly appreciate your help. Thank you. $\endgroup$
    – user98502
    Commented Apr 20 at 20:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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