30visualizaciones (últimos 30días)
Mostrar comentarios más antiguos
Chris Nemecek el 31 de Mayo de 2024 a las 19:01
Comentada: William Rose el 2 de Jun. de 2024 a las 0:28
- example.mat
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 comentario Mostrar -1 comentarios más antiguosOcultar -1 comentarios más antiguos
Mostrar -1 comentarios más antiguosOcultar -1 comentarios más antiguos
John D'Errico el 31 de Mayo de 2024 a las 23:41
Enlace directo a este comentario
https://la.mathworks.com/matlabcentral/answers/2124486-contour-plot-from-x-and-y-data-points-with-corresponding-contour-level#comment_3177161
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.
Iniciar sesión para comentar.
Iniciar sesión para responder a esta pregunta.
Respuestas (1)
William Rose el 31 de Mayo de 2024 a las 22:13
Abrir en MATLAB Online
- example.mat
@Chris Nemecek.
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 comentarios Mostrar 2 comentarios más antiguosOcultar 2 comentarios más antiguos
Mostrar 2 comentarios más antiguosOcultar 2 comentarios más antiguos
William Rose el 1 de Jun. de 2024 a las 2:13
Enlace directo a este comentario
https://la.mathworks.com/matlabcentral/answers/2124486-contour-plot-from-x-and-y-data-points-with-corresponding-contour-level#comment_3177186
Editada: William Rose el 1 de Jun. de 2024 a las 2:17
Abrir en MATLAB Online
- example.mat
@Chris Nemecek,
The lines below compute and display the min and max values of x and y, and the z value, for each level.
The results show that the min and max x and y INcrease by sqrt(10) at each level, and the z value (density) DEcreases by a factor of exactly 10 with each level. Therefore this data is simulated, not measured from experiment, and density along the perimeter times area enclosed = constant. You could use only the outer ring of points (level 11) data to exactly predict the density for all other x,y points, including, but not limited to, the points on the other contour lines. You could fill in a grid if you wanted.
A=load('example');
NL=length(A.T); % number of levels=[];
for i=1:NL
d(:,:,i)=table2array(A.T{i});
end
xmin=min(squeeze(d(:,1,:))); xmax=max(squeeze(d(:,1,:)));
ymin=min(squeeze(d(:,2,:))); ymax=max(squeeze(d(:,2,:)));
z=mean(squeeze(d(:,3,:)));
for i=1:NL
fprintf('%.2e %.2e %.2e %.2e %.2e\n',xmin(i),xmax(i),ymin(i),ymax(i),z(i))
end
-8.21e-07 5.64e-03 -1.55e-03 1.55e-03 1.00e+00-2.60e-06 1.78e-02 -4.90e-03 4.90e-03 1.00e-01-8.21e-06 5.64e-02 -1.55e-02 1.55e-02 1.00e-02-2.60e-05 1.78e-01 -4.90e-02 4.90e-02 1.00e-03-8.21e-05 5.64e-01 -1.55e-01 1.55e-01 1.00e-04-2.60e-04 1.78e+00 -4.90e-01 4.90e-01 1.00e-05-8.21e-04 5.64e+00 -1.55e+00 1.55e+00 1.00e-06-2.60e-03 1.78e+01 -4.90e+00 4.90e+00 1.00e-07-8.21e-03 5.64e+01 -1.55e+01 1.55e+01 1.00e-08-2.60e-02 1.78e+02 -4.90e+01 4.90e+01 1.00e-09-8.21e-02 5.64e+02 -1.55e+02 1.55e+02 1.00e-10
Chris Nemecek el 1 de Jun. de 2024 a las 14:58
Enlace directo a este comentario
https://la.mathworks.com/matlabcentral/answers/2124486-contour-plot-from-x-and-y-data-points-with-corresponding-contour-level#comment_3177356
Thanks for the thoughts. I would really want to use contour() such that I can get nice labels of each contour level and bd able to correlate to cdata, clim, etc. though. If the spatial domain is too big to use interpp2() or griddata(), this may prevent what I'm attempting to do.
William Rose el 2 de Jun. de 2024 a las 0:27
Enlace directo a este comentario
https://la.mathworks.com/matlabcentral/answers/2124486-contour-plot-from-x-and-y-data-points-with-corresponding-contour-level#comment_3177541
@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.
William Rose el 2 de Jun. de 2024 a las 0:28
Enlace directo a este comentario
https://la.mathworks.com/matlabcentral/answers/2124486-contour-plot-from-x-and-y-data-points-with-corresponding-contour-level#comment_3177546
@Chris Nemecek, this data reminds me of a convection-diffusion problem.
Iniciar sesión para comentar.
Iniciar sesión para responder a esta pregunta.
Se ha producido un error
No se puede completar la acción debido a los cambios realizados en la página. Vuelva a cargar la página para ver el estado actualizado.
Seleccione un país/idioma
Seleccione un país/idioma para obtener contenido traducido, si está disponible, y ver eventos y ofertas de productos y servicios locales. Según su ubicación geográfica, recomendamos que seleccione: .
También puede seleccionar uno de estos países/idiomas:
América
- América Latina (Español)
- Canada (English)
- United States (English)
Europa
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- Deutsch
- English
- Français
- United Kingdom(English)
Asia-Pacífico
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)
Comuníquese con su oficina local