How can I specify the region of the contour plot ?
9 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I want to use contourf on a data set I have. The issue is that the data points for which the contour levels are avaliable, are concentrated in a specfic region. I want to restrict the contour plot to that region. How can I restrict the contour plot to this region? I have attached here the reference image. Is there any way I can specify the regions manually ?
0 commentaires
Réponses (2)
Star Strider
le 15 Jan 2024
Without the data or the contour levels labels, a precise reply is not possible. If you know that all the data are either greater than a specific value or less than a specific value (or within a range of values), you can restrict the data given to contourf to the data in that specific range.
imshow(imread('untitled.png'))
[X,Y,Z] = peaks(50);
contourf(X, Y, Z, 'ShowText','on')
Z(Z < 2) = NaN; % Restrict 'Z' To Values Greater Than 2
figure
contourf(X, Y, Z, 'ShowText','on')
I am not certain what result you want.
.
0 commentaires
Hassaan
le 15 Jan 2024
% Sample data (replace with your actual data)
[X, Y] = meshgrid(-10:0.1:10, -10:0.1:10);
Z = peaks(X, Y); % Replace with your actual Z data
% Define the region of interest
x_min = -5;
x_max = 5;
y_min = -5;
y_max = 5;
% Create a mask to restrict the contour plot to the region
mask = (X >= x_min) & (X <= x_max) & (Y >= y_min) & (Y <= y_max);
% Apply the mask to your data
Z_filtered = Z;
Z_filtered(~mask) = NaN; % Set values outside the region to NaN
% Plot the contour plot within the specified region
contourf(X, Y, Z_filtered, 20); % Adjust the number of contour levels as needed
colorbar; % Add a colorbar for reference
xlabel('X-axis');
ylabel('Y-axis');
title('Contour Plot in Specified Region');
The mask is created to restrict the contour plot to the region defined by x_min, x_max, y_min, and y_max. Adjust these values according to your specific region of interest and data.
------------------------------------------------------------------------------------------------------------------------------------------------
If you find the solution helpful and it resolves your issue, it would be greatly appreciated if you could accept the answer. Also, leaving an upvote and a comment are also wonderful ways to provide feedback.
Professional Interests
- Technical Services and Consulting
- Embedded Systems | Firmware Developement | Simulations
- Electrical and Electronics Engineering
Feel free to contact me.
0 commentaires
Voir également
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!



