Filled Contour Plot Error
显示 更早的评论
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?
采纳的回答
更多回答(1 个)
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.
类别
在 帮助中心 和 File Exchange 中查找有关 Contour Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!






