I want to my contour plot to look like the one from mathematica?
1 次查看(过去 30 天)
显示 更早的评论
I am trying to repeat the format of countour plot from mathematica in matlab.

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.

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 个评论
dpb
2019-7-10
编辑:dpb
2019-7-10
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...
回答(1 个)
dpb
2019-7-10
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

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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Contour Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!