I want to my contour plot to look like the one from mathematica?
9 views (last 30 days)
Show older comments
I am trying to repeat the format of countour plot from mathematica in matlab.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/228447/image.png)
the above picture is what I want the lot to look like to look like. I am providing how I tried to achive the task.
I used the following code
bx = readmatrix('BX X,Z.xlsx');
bz = readmatrix('BZ X,Z.xlsx');
B=sqrt(bx.^2+bz.^2);
x=-12.4:0.5:12.6;
y=24:-2:0;
[Y,X]=meshgrid(x,y);
%surf(Y,X,transpose(B));
%hold on;
contour(Y,X,transpose(B),'fill','on');
%colormap(parula(18));
xlabel('X-axis');
ylabel('Z-axis');
zlabel('B-value');
title('the value of B data');
colorbar;
however the code does not generate the same picture. it gives somethong like the picture below.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/228448/image.png)
I am also providing how it is done in mathematica. as follows
dataBx = Import["BvsY_1207.xlsx"] [[1]];
dataBz = Import["BvsY_1207.xlsx"] [[2]];
dataBz = dataBz + .06;
ClearAll[Bx, Bz, x, z];
listx = Range[0, 25, 0.5];
listx = listx - 12.4;
x = Transpose[Table[listx, {i, 13}]];
listy = 12 - Range[0, 24, 2];
y = Table[listy, {i, 51}];
dataB = Sqrt[dataBx^2 + dataBz^2];
B = Transpose[{Flatten[y], Flatten[x], Flatten[dataB]}];
ListContourPlot[B, InterpolationOrder -> 4, Contours -> 18,
ContourLines -> False,
BaseStyle -> {FontFamily -> "Times", FontSize -> 24},
FrameLabel -> {"Y/mm", "X/mm", "" , "" }, PlotLegends -> Automatic]
providing the excel data for the matlab code as attachment.
3 Comments
dpb
on 10 Jul 2019
Edited: dpb
on 10 Jul 2019
Well, you told Mathematica to use 18 contour levels but didn't do the same with MATLAB using the default.
See the optional input parameter that sets the number of conotour levels, n, to at least have a somewhat level playing field before casting too many stones.
I don't have any idea about what the InterpolationOrder argument might be doing...
Answers (1)
dpb
on 10 Jul 2019
One of the examples from ML doc (peaks function) with x/y limits expanded to more or less mimic the kind of figure you have results in the following
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/228487/image.jpeg)
which I'd say is certainly comparable to what Mathematica did. That's just
[X,Y,Z]=peaks;
contour(X,Y,Z,18,'fill','on')
xlim([-2 2])
ylim([0 3])
0 Comments
See Also
Categories
Find more on Contour Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!