Effacer les filtres
Effacer les filtres

How to create a "contour" plot with a varying X and Y vector values?

36 vues (au cours des 30 derniers jours)
Oscar Aguilar-Cerna
Oscar Aguilar-Cerna le 11 Mai 2023
I am trying to plot a 3rd variable on an x and y plane, and would like to make it into a contour, specifically with the contourf(x,y,z) function. Unfortunately, my x and y values are not in strictly increasing or decreasing order, and there are repeated values, which the contourf function does not accept. I cannot use the sort function for my x and y vectors as they are associated with each other, and the sort function will mess up their pairings. Is there another function that is similar to contourf that will allow my x and y vectors? I have already looked into the pcolor and contour functions, but they are not giving me results that I would like. Basically, I want to have my x and y values in any order, and for repetition to be allowed. I cannot share my raw data as it is confidential.
Below is the scatter plot version. I want this plot to simply be a contour version of this scatterplot, with a colorbar to see the variance in the 3rd variable as a function of the other two variables.
Here is a sample of my code:
%%creating a circle
%// radius
r = 0.38;
%// center
c = [0 0];
pos = [c-r 2*r 2*r];
rectangle('Position',pos,'Curvature',[1 1])
hold on
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
dz = diag(z); %creating my z vector into a diagonal matrix
%scatter(x,y,z,'filled'); %previous plot, I want to convert it into a
%contour plot
contourf(x,y,dz); % contourf only takes my 3rd variable as a matrix, I am not sure if
%this diagonal vector will work for my needs.
title('Velocity Distribution for Natural Gas Injector');
xlabel('X position [inches]');
ylabel('Y Position [inches]');
a=colorbar;
ylabel(a,'Velocity [ft/s]','FontSize',10,'Rotation',270);
a.Label.Position(1) = 0.95;
clim([110 140]);
axis equal
hold off

Réponses (2)

Mann Baidi
Mann Baidi le 28 Août 2023
Modifié(e) : Mann Baidi le 3 Nov 2023
Hi Oscar,
I understand that you are facing issue in using the “contour” function as you don’t have the vectors in increasing order. I would suggest you use the “plot3” function.
You can find the documentation of the function below:
Hope this helps!

Walter Roberson
Walter Roberson le 3 Nov 2023
contourf() is not applicable to volumes. To contour on volumes, use isosurface -- usually with transparency so you can see "inside" the shells.
You cannot create meaningful contours when there are duplicate spatial points with different f values: the existence of such points would imply that that one point was simultaneously every value between the min() and max() of the f at that point, since contouring has the implicit assumption of continuity.

Catégories

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

Community Treasure Hunt

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

Start Hunting!

Translated by