contour plot using x y z data

조회 수: 19 (최근 30일)
titu s
titu s 2021년 7월 16일
댓글: Voss 2022년 3월 15일
I want to make a colour filled beautiful contour map using my data attached and want to write A B C D E F G H on the map itself at the scatter point
dt y x z
A 31.53 77.95 0.112
B 31.40 78.35 0.032
C 31.66 78.03 -0.001
D 31.48 77.75 -0.092
E 32.28 78.45 -0.113
F 31.99 76.42 -0.184
G 31.64 77.34 -0.016
H 32.50 75.62 -0.121
i tried contourf(x,y z)..but getting errors.
please suggest a solution.

채택된 답변

Walter Roberson
Walter Roberson 2021년 7월 16일
However, that uses patch() to put in the contours, and is not compatible with using clabel(), so you would have to text() in appropriate places.
See https://www.mathworks.com/help/matlab/math/interpolating-scattered-data.html#bsovi2t for a different approach which is compatible with clabel()
If you do use clabel() you will not be able to directly control the text. However you can record the first output of clabel(), which will be the handles to the text objects, and you can then modify the String property of those text objects.
  댓글 수: 3
Richard Sanders
Richard Sanders 2022년 3월 15일
Hi there,
I know this is a pretty old post but I've been doing something similar and am not very familiar with Matlab yet, hopefully you can still help me. Is it possible to have the space between the lines filled with the according colours? Also possibly important to note that I'm working with a fairly large dataset (almost 2000 values for x, y and z each).
Voss
Voss 2022년 3월 15일
@Richard Sanders To have a filled contour, you can use contourf() in place of contour():
data = {
'A' 31.53 77.95 0.112
'B' 31.40 78.35 0.032
'C' 31.66 78.03 -0.001
'D' 31.48 77.75 -0.092
'E' 32.28 78.45 -0.113
'F' 31.99 76.42 -0.184
'G' 31.64 77.34 -0.016
'H' 32.50 75.62 -0.121};
dt = data(:,1);
y = vertcat(data{:,2});
x = vertcat(data{:,3});
z = vertcat(data{:,4});
N = 20;
[X, Y] = meshgrid(linspace(min(x)-0.2, max(x)+0.2, N), linspace(min(y)-0.2, max(y)+0.2, N));
F = scatteredInterpolant(x, y, z);
Z = F(X, Y);
[C,h] = contourf(X, Y, Z);
clabel(C)
text(x, y, dt);
colorbar()

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Contour Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by