How to plot contour of an xy plot with a constant value?

14 visualizaciones (últimos 30 días)
UH
UH el 11 de Dic. de 2023
Respondida: Nipun el 21 de Dic. de 2023
I have several data sets (I have selected two lines in this case. I want to plot them as contour lines with different z values. For example, I want to plot the xy-data with z values as 40 and 30. As the lines extend beyond my area of interest, the current are of interest is 0 to 120 in x and 0 to 220 in y axis. I tried using meshgrid which I have used for plotting contour plots but I cannot convert these known values of lines into contours.Your help will be much appreciated.
xy = readtable('xy_data.xlsx');
x1 = xy.x40;
y1 = xy.y40;
x2 = xy.x30;
y2 = xy.y30;
figure
rectangle('Position',[0 0 120 220]) % the contour line can be only drawn in this box
axis equal
hold on
plot(x1,y1)
plot(x2,y2)

Respuesta aceptada

Mathieu NOE
Mathieu NOE el 11 de Dic. de 2023
hello
why not simply use xlim and ylim to plot the required area ?
xy = readtable('xy_data.xlsx');
x1 = xy.x40;
y1 = xy.y40;
x2 = xy.x30;
y2 = xy.y30;
figure
% rectangle('Position',[0 0 120 220]) % the contour line can be only drawn in this box
axis equal
hold on
plot(x1,y1)
plot(x2,y2)
xlim([0 120])
ylim([0 220])
  11 comentarios
UH
UH el 14 de Dic. de 2023
Thank you. It works perfectly. All the best.

Iniciar sesión para comentar.

Más respuestas (1)

Nipun
Nipun el 21 de Dic. de 2023
Hi UH,
I understand that you have two sets of xy-data representing lines and want to create a contour plot with specified z values. The area of interest for the plot is defined as 0 to 120 in the x-axis and 0 to 220 in the y-axis.
Based on the provided information, I see that you have attempted to use meshgrid for plotting contour plots but are facing challenges converting the known values of lines into contours.
I recommend using "xlim" and "ylim" to plot the required area. The link to documentation is attached below
I have modified your code to help you with the same
xy = readtable('xy_data.xlsx');
x1 = xy.x40;
y1 = xy.y40;
x2 = xy.x30;
y2 = xy.y30;
figure
%% Commenting the rectangle function, use limits instead
% rectangle('Position',[0 0 120 220]) % the contour line can be only drawn in this box
axis equal
hold on
plot(x1,y1)
plot(x2,y2)
%% adding limits
xlim([0 120]);
ylim([0 220]);
Link to documentation:
  1. Set or query x-axis limits - MATLAB xlim - MathWorks India
  2. Specify Axis Limits - MATLAB & Simulink - MathWorks India
Hope this helps.
Regards,
Nipun

Categorías

Más información sobre Contour Plots en Help Center y File Exchange.

Productos


Versión

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by