My code is:

data1 = Table[Sin[x*y], {x, -3, 3, 0.1}, {y, -3, 3, 0.1}];
data2 = Reverse[data1, {1, 2}];
ListContourPlot[data1 - data2, Contours -> 20, 
PlotLegends -> Automatic]

and, as Output, I obtain:

enter image description here

My question: it is easy to see that the Output is approximately zero. How can I fix my Output to see with PlotLegends that it is zero?

My attempt was to reduce number of contours: enter image description here

But result not so pretty good. I assume that I can fix ColorFunction for Contours (may be reduce its step...?) but don't understand how. Can anybody help me?

  • $\begingroup$ ListContourPlot[data1 - data2 // Chop, Contours -> 20, PlotLegends -> Automatic]? $\endgroup$ – march Apr 26 at 15:27
  • $\begingroup$ @march Thank you! But what if the difference between two data sets not so small, but I would like to obtain zero? $\endgroup$ – Artem Alexandrov Apr 26 at 15:33
  • $\begingroup$ Well, you've set Contours -> 20, so it's going to try to find 20 contours unless it knows that all the values are exactly the same (for instance, by Chopping as we did). You can somewhat artificially increase the PlotRange by adding PlotRange -> {-10, 10}. I'm not sure why you want to do this, though. If the data really are larger, why do you want to force them to be zero? In any case, you can also add a second option to Chop. By default, it sets to zero any number less than 10^-10, but you can change this by doing Chop[number, 10^-8], for instance. $\endgroup$ – march Apr 26 at 15:53

Your Answer

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

Browse other questions tagged or ask your own question.