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 Center および File ExchangeContour Plots についてさらに検索

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by