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

14 vues (au cours des 30 derniers jours)
UH
UH le 11 Déc 2023
Réponse apportée : Nipun le 21 Déc 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)

Réponse acceptée

Mathieu NOE
Mathieu NOE le 11 Déc 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 commentaires
UH
UH le 14 Déc 2023
Thank you. It works perfectly. All the best.
Mathieu NOE
Mathieu NOE le 19 Déc 2023
My pleasure !

Connectez-vous pour commenter.

Plus de réponses (1)

Nipun
Nipun le 21 Déc 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

Catégories

En savoir plus sur Contour Plots dans Help Center et File Exchange

Produits


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by