# Can I make a smooth contour plot with Mathematica?

Some material I read gives a really good contour plot (img1), but when I use the same math to analyze some other sets of data, and make the contour plot with MMA, it gives some ladder-like distribution (img2). Can I narrow them and make it smoother?

By smoother, I mean the color of model contour plot is blending from red to blue, and every stage of them is not that significant (they are more like a blend of two similar color), but in my plot the neighbor stage just jump to another color, like from blue to green, which makes it quite rigid. And the plot legend is different, so I wonder maybe I can make the plot range smaller to the concentrate part and narrow the difference between neighbor color?

(Btw, I tried plotrange->All, but things doesn’t go well(img3))

The code is as followed:

chi2Dis=0.542819 (-0.237992 + (1. (x^2 + y^2)^0.28 (1 +
1/40 Sqrt[
x^2 + y^2])^2.66)/((142.325 + (6367.9 - x)^2 + (-93. -
y)^2 - 23.86 Sqrt[(6367.9 - x)^2 + (-93. - y)^2]
Cos[0.174048 - (Sqrt[x^2 + y^2] (0.015 + ArcTan[y/x]))/
Sqrt[(6367.9 - x)^2 + (-93. - y)^2]])^0.56 (1 +
1/40 (142.325 + (6367.9 - x)^2 + (-93. - y)^2 -
23.86 Sqrt[(6367.9 - x)^2 + (-93. - y)^2]
Cos[0.174048 - (Sqrt[x^2 + y^2] (0.015 + ArcTan[y/x]))/
Sqrt[(6367.9 - x)^2 + (-93. - y)^2]]))^2.66))^2 +
0.542819 (-0.920296 + (1. (x^2 + y^2)^0.28 (1 +
1/40 Sqrt[
x^2 + y^2])^2.66)/((30.1401 + (6367.9 - x)^2 + (-93. -
y)^2 - 10.98 Sqrt[(6367.9 - x)^2 + (-93. - y)^2]
Cos[1.16923 - (Sqrt[x^2 + y^2] (0.015 + ArcTan[y/x]))/
Sqrt[(6367.9 - x)^2 + (-93. - y)^2]])^0.56 (1 +
1/40 (30.1401 + (6367.9 - x)^2 + (-93. - y)^2 -
10.98 Sqrt[(6367.9 - x)^2 + (-93. - y)^2]
Cos[1.16923 - (Sqrt[x^2 + y^2] (0.015 + ArcTan[y/x]))/
Sqrt[(6367.9 - x)^2 + (-93. - y)^2]]))^2.66))^2 +
0.542819 (-2.61093 + (1. (x^2 + y^2)^0.28 (1 +
1/40 Sqrt[
x^2 + y^2])^2.66)/((42.6409 + (6367.9 - x)^2 + (-93. -
y)^2 - 13.06 Sqrt[(6367.9 - x)^2 + (-93. - y)^2]
Cos[1.32055 - (Sqrt[x^2 + y^2] (0.015 + ArcTan[y/x]))/
Sqrt[(6367.9 - x)^2 + (-93. - y)^2]])^0.56 (1 +
1/40 (42.6409 + (6367.9 - x)^2 + (-93. - y)^2 -
13.06 Sqrt[(6367.9 - x)^2 + (-93. - y)^2]
Cos[1.32055 - (Sqrt[x^2 + y^2] (0.015 + ArcTan[y/x]))/
Sqrt[(6367.9 - x)^2 + (-93. - y)^2]]))^2.66))^2 +
0.542819 (-3.59972 + (1. (x^2 + y^2)^0.28 (1 +
1/40 Sqrt[
x^2 + y^2])^2.66)/((28.9444 + (6367.9 - x)^2 + (-93. -
y)^2 - 10.76 Sqrt[(6367.9 - x)^2 + (-93. - y)^2]
Cos[2.77748 + (Sqrt[x^2 + y^2] (0.015 + ArcTan[y/x]))/
Sqrt[(6367.9 - x)^2 + (-93. - y)^2]])^0.56 (1 +
1/40 (28.9444 + (6367.9 - x)^2 + (-93. - y)^2 -
10.76 Sqrt[(6367.9 - x)^2 + (-93. - y)^2]
Cos[2.77748 + (Sqrt[x^2 + y^2] (0.015 + ArcTan[y/x]))/
Sqrt[(6367.9 - x)^2 + (-93. - y)^2]]))^2.66))^2;
ContourPlot[chi2Dis,{x,-15000,25000},{y,-10000,10000},
ColorFunction->”Rainbow”,PlotLegends->Autotmatic]


• Welcome to Mathematica SE! Please provide your code you used to generate the example figure such that we could make more precise recommondations. Also, it is not really clear what is the problem. Do you need the z-axis to cover a larger span? The purple and white just indicate the clipping as Mathematica has tried to guess the 'interesting region" of the z-scale. – Johu Sep 4 '18 at 14:48
• Given the relatively simple shapes of the contours, you can get smoother contours using the PlotPoints option. Maybe try PlotPoints -> 100. (And using @Johu 's suggestion of PlotRange -> All is essential to remove the "white" area.) Also, to get the contour plot to look more like the first two examples you should use PlotRangeClipping -> True. That will remove the white space near the axes. – JimB Sep 4 '18 at 15:41
• Thanks for the update! I think you have something wrong with your function. As you can see, the relative changes on the plot are are really small. – Johu Sep 4 '18 at 16:58
• Just to echo that the function or its evaluation with machine precision numbers is likely not what you need. If one tries chi2Dis /. {x -> 1, y -> 1} and chi2Dis /. {x -> 5000, y -> 5000}, one gets 11.2247 for both. And the same for pretty much any {x,y} values (except {x -> 0, y -> 0} as that gives an error. – JimB Sep 4 '18 at 19:10

You need to use the option PlotRange->All of the ContourPlot, I guess. If not, please be more specific about which feature of the plot is not as you would like.

If you really need "smoothing" of the countours by increased sampling desnity, I recommend using option MaxRecursion->3 or higher.

Edit 1

I got a little bit more reasonablt plot by removing the vertical offset, and plotting values in log-scale.

DensityPlot[
Evaluate@Log10@
Abs[((chi2Dis /. {x -> x2, y -> y2}) - (chi2Dis /. {x -> 100000,
y -> 100000}))], {x2, -15000, 25000 }, {y2, -10000 , 10000 },
PlotLegends -> Automatic, PlotPoints -> 40, Mesh -> All,
MaxRecursion -> 6]


ContourPlot[
Evaluate@Log10@
Abs[((chi2Dis /. {x -> x2, y -> y2}) - (chi2Dis /. {x -> -10,
y -> 10}))], {x2, -15000, 25000 }, {y2, -10000 , 10000 },
PlotLegends -> Automatic, PlotPoints -> 40, MaxRecursion -> 2,
PlotRange -> Full]


I think you have a problem with the thing you want to plot. The function is very sharp around 0 flat everywhere else. Preahps you should check, if you have made an error with the dimensions when choosing your function.

Edit 2

From the problem description I know also understood the wish to devide the colour scale into more segments. This can be achived using Contours option.

ContourPlot[
Evaluate@Log10@
Abs[((chi2Dis /. {x -> x2, y -> y2}) - (chi2Dis /. {x -> -10,
y -> 10}))], {x2, -15000, 25000 }, {y2, -10000 , 10000 },
PlotLegends -> Automatic, PlotPoints -> 40, MaxRecursion -> 4,
Contours -> 20, ColorFunction -> "Rainbow"]