contour plot using x y z data
18 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
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
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
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 Center 和 File Exchange 中查找有关 Contour Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

