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

조회 수: 14 (최근 30일)
UH
UH 2023년 12월 11일
답변: Nipun 2023년 12월 21일
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)

채택된 답변

Mathieu NOE
Mathieu NOE 2023년 12월 11일
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
UH
UH 2023년 12월 14일
Thank you. It works perfectly. All the best.
Mathieu NOE
Mathieu NOE 2023년 12월 19일
My pleasure !

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Nipun
Nipun 2023년 12월 21일
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

카테고리

Help CenterFile Exchange에서 Contour Plots에 대해 자세히 알아보기

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by