I want to my contour plot to look like the one from mathematica?

6 Ansichten (letzte 30 Tage)
Amanuel Negash
Amanuel Negash am 10 Jul. 2019
Beantwortet: dpb am 10 Jul. 2019
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 Kommentare
Amanuel Negash
Amanuel Negash am 10 Jul. 2019
it is not its just that the contour coloring is not as good as mathematica code.
dpb
dpb am 10 Jul. 2019
Bearbeitet: dpb am 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...

Melden Sie sich an, um zu kommentieren.

Antworten (1)

dpb
dpb am 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
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])

Kategorien

Mehr zu Contour Plots finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by