Contour plot from x and y data points with corresponding contour level

5 visualizzazioni (ultimi 30 giorni)
I have sets of x and y data points that correspond to a specific contour level. For example (x1,y1) and (x2,y2) correspond to a contour level of 0.1 and (x3,y3) and (x4,y4) correspond to a contour level of 0.01. How do I plot these using the contour function?
In the attached .mat file, I have a cell array of tables. Each table has x and y data and the corresponding contour level (which is labeled Density). Basically, if you plot the x and y data using plot() it will create the contour, but I want to use contour() to plot to leverage labeling contours.
  1 Commento
John D'Errico
John D'Errico il 31 Mag 2024
In the example for gridfit, I show how to recover a surface from a set of contours. (They actually came from a topographic map in the area of my home.) But you don't want to do that.
If all you want to do is show the contours, with labels on them, then just use plot, then use text to label the contour. There is no need to go through contour at all.

Accedi per commentare.

Risposte (1)

William Rose
William Rose il 31 Mag 2024
The code below plots the x,y coords of the data, in order to give insight get into the spatial sampling. The code makes 4 plots of all the data. The plots differ only in their axis limits. The 4 plots show that the x,y coordinates at each level differ by a factor of 10 or so from the next levels.
Matllab's contour() want data sampled on a rectangular grid. You could use interp2() to resample this data onto a rectangular grid, but the reuslts would not be very good, due to the different scales of spatial sampling at each level.
A=load('example');
d=[];
for i=1:length(A.T)
d=[d; table2array(A.T{i})];
end
Np=150; % number of points in each level
NL=length(A.T); % number of levels
colors=hsv2rgb([linspace(0,1,NL+1)',ones(NL+1,2)]); %
figure
subplot(221)
for i=1:NL
plot(d(Np*i-149:Np*i,1),d(Np*i-149:Np*i,2),'Marker','+','Color',colors(i,:));
hold on;
end
xlabel('X'); ylabel('Y'); grid on; legend()
subplot(222)
for i=1:NL
plot(d(Np*i-149:Np*i,1),d(Np*i-149:Np*i,2),'Marker','+','Color',colors(i,:));
hold on;
end
xlabel('X'); ylabel('Y'); grid on; xlim([0 15]); ylim([-10 10])
subplot(223)
for i=1:NL
plot(d(Np*i-149:Np*i,1),d(Np*i-149:Np*i,2),'Marker','+','Color',colors(i,:));
hold on;
end
xlabel('X'); ylabel('Y'); grid on; xlim([0 1.5]); ylim([-1 1])
subplot(224)
for i=1:NL
plot(d(Np*i-149:Np*i,1),d(Np*i-149:Np*i,2),'Marker','+','Color',colors(i,:));
hold on;
end
xlabel('X'); ylabel('Y'); grid on; xlim([0 .15]); ylim([-.1 .1])
  4 Commenti
William Rose
William Rose il 2 Giu 2024
@Chris Nemecek, I definitely agree with you that the capabilities and options available with contour() and related functions are very nice to be able to use.
What makes your data different from the image you provided in your recent comment is that your data spans ten orders of magnitude in z and 5 orders of magnitude in x and y. A common repsonse to that would be to use log scales. And we can do that for z, but not for x and y, since the x and y ranges include 0 and negative and positive values.
The step sizes between grid lines need not be uniform. This could be useful in your case.

Accedi per commentare.

Categorie

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

Prodotti


Release

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by