contour plot using x y z data

22 visualizzazioni (ultimi 30 giorni)
titu s
titu s il 16 Lug 2021
Commentato: Voss il 15 Mar 2022
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.

Risposta accettata

Walter Roberson
Walter Roberson il 16 Lug 2021
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 Commenti
Richard Sanders
Richard Sanders il 15 Mar 2022
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 il 15 Mar 2022
@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()

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Contour Plots in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by