How can I specify the region of the contour plot ?
9 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (2 件)
Star Strider
2024 年 1 月 15 日
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 件のコメント
Hassaan
2024 年 1 月 15 日
% 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 件のコメント
参考
カテゴリ
Help Center および File Exchange で Contour Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



