Filled Contour Plot Error
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have some functions with asymptotes and I want to get filled contour plot.
For example;
When I plot the function 3D and rotate it, I get:
First Method using fcontour
figure (1)
func=@(x,t) (16/3).*(12.*((-4)+4.*exp(1).^(8.*((-1/16)+(-2).*t+x))).^(-1)+(-4)*((-1/16)+(-2).*t+x));
fsurf(@(x,t) func(x,t),[-1 1 -1 1],'ShowContours','on');
zlim([-50,50]);
caxis([-50,50]);
colorbar;
colormap jet;
xlabel('x');
ylabel('t');
Second Method using contourf
figure (2)
[X, T] = meshgrid(linspace(-1,1), linspace(-1,1));
F=func(X,T);
contourf(X,T,F);
zlim([-50,50]);
caxis([-50,50]);
colorbar;
colormap jet;
xlabel('x');
ylabel('t');
As you see the colors in the last two figures are different from the first figure.
How to get the correct filled contour plots by automatically selecting appropriate contour levels for any functions?
0 commentaires
Réponse acceptée
Star Strider
le 3 Jan 2022
Modifié(e) : Star Strider
le 3 Jan 2022
Request more contour levels (here I requested 150) —
func=@(x,t) (16/3).*(12.*((-4)+4.*exp(1).^(8.*((-1/16)+(-2).*t+x))).^(-1)+(-4)*((-1/16)+(-2).*t+x));
figure (2)
[X, T] = meshgrid(linspace(-1,1), linspace(-1,1));
F=func(X,T);
contourf(X,T,F,150);
zlim([-50,50]);
caxis([-50,50]);
colorbar;
colormap jet;
xlabel('x');
ylabel('t');
EDIT — (3 Jan 2022 at 14:16)
The surf plot (without rotating it) is —
figure
surf(X,T,F);
zlim([-50,50]);
caxis([-50,50]);
colorbar;
colormap jet;
xlabel('x');
ylabel('t');
so ‘automatically selecting the contour levels’ is going to be a challenge if it is necessary to see all of them. Another option of course is to select them with a specific vector of levels, perhaps 25 so this can be adapted to other functions —
lims = [-50 50]; % Limits To Be Used In The Plot
N = 15; % Number Of Contour Levels Desired
clvls = linspace(lims(1), lims(2), N); % Define Contour Levels
figure
contourf(X,T,F,clvls);
zlim(lims);
caxis(lims);
colorbar;
colormap jet;
xlabel('x');
ylabel('t');
The ‘clvls’ vector obviously must be defined before the contour call, so one way of making everything adaptive is to define the limits first as a separate 2-element vector, and then let zlim, caxis and ‘clvls’ use them as arguments. I did that in the last figure. Defining the limits is something you must provide, depending on how the plots are supposed to describe the data.
.
3 commentaires
Walter Roberson
le 3 Jan 2022
How to get the correct filled contour plots by automatically selecting appropriate contour levels for any functions?
You cannot. "Appropriate" contour level depends upon the interpretation of interest at the time, not upon the data itself.
... Especially, as in cases like this, when you have a discontinuity.
Star Strider
le 3 Jan 2022
1) I am not certain what ‘the first figure in the quesiton’ refers to. If it is the rotated surface plot, the two are essentially the same. If it refers to the first contour plot, that has to do with the number of contours plotted. Plotting fewer contours includes more levels in each contour, so the values in the blank area in the lower right get included in that contour.
2) I am not certain what the problem is. Deciding on the contours for a specific function depends on the values of the function. Since I have no way of determining what the desired result is, I have no way of determining how best to define them.
‘How to get the correct filled contour plots by automatically selecting appropriate contour levels for any functions?’
It is possible to define the contour levels as I did here with the ‘clvls’ vector. The contours do not have to be regularly-spaced, so it would also be appropriate to use the logspace function or simply defining them manually or with respect to a function that would produce a vector of monotonically-increasing values (or one value if the value is a (1x2) vector with both elements being the same).
There is no one specific method of defining the contours. That depends on the data plotted and what the desired result is.
Plus de réponses (1)
Walter Roberson
le 3 Jan 2022
func=@(x,t) (16/3).*(12.*((-4)+4.*exp(8.*((-1/16)+(-2).*t+x))).^(-1)+(-4)*((-1/16)+(-2).*t+x));
syms x t
fun(x,t) = simplify(func(x,t))
figure
fsurf(fun, [-1 1 -1 1]);
view([0 90]); caxis([-50 50]); colorbar(); colormap(jet)
figure
fsurf(fun, [-1 1 -1 1], 'showcontours', true)
view([0 90]); caxis([-50 50]); colorbar(); colormap(jet)
figure
fsurf(func, [-1 1 -1 1],'showcontours', true)
view([0 90]); caxis([-50 50]); colorbar(); colormap(jet)
figure
[X, T] = meshgrid(linspace(-1,1), linspace(-1,1));
F=func(X,T);
contourf(X, T, F, -50:10:50);
caxis([-50 50]); colorbar(); colormap(jet)
The white in the bottom right corner is a section with F less than the lowest contour.
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!