How to eliminate transition section in contourf function;

4 次查看(过去 30 天)
The value in yellew is 4, and the value in blue is 1, there are not value between 4 and 1, but the figure by contourf has transition section.

采纳的回答

Walter Roberson
Walter Roberson 2023-8-20
Contour calculations rely upon the idea that if you have two nearby locations with known values, that at some point between the two locations, the function must have gone through every value between the two known values.
Contour calculations are only suitable for functions that obey the Intermediate Value Theorem https://en.wikipedia.org/wiki/Intermediate_value_theorem
If your array has locations with value 4 and adjacent ones with value 1, and there is no transition area, then your array does not represent a function that is suitable for contour plots. You will need to section the array according to boundaries in which the Intermediate Values do not exist, and contour each section separately.

更多回答(1 个)

Mrutyunjaya Hiremath
% Sample data
[X, Y, Z] = peaks(100);
% Create a figure
figure;
% Create a filled contour plot
contourf(X, Y, Z);
% Use a default colormap and display a colorbar
colormap(parula);
colorbar;
% Title
title('Without Modifications');
% Sample data
[X, Y, Z] = peaks(100);
% Define contour levels explicitly
contourLevels = [-7:1:7];
% Create a new figure
figure;
% Create a filled contour plot with specified contour levels and no line style
contourf(X, Y, Z, contourLevels, 'LineStyle', 'none');
% Use a colormap that emphasizes discrete levels and display a colorbar
colormap(jet(length(contourLevels)-1));
colorbar;
% Title
title('With Modifications');

类别

Help CenterFile Exchange 中查找有关 Contour Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by