MATLAB Answers

Waterfall plot not showing correctly

조회 수: 7(최근 30일)
Bill Tubbs
Bill Tubbs 2021년 6월 18일
댓글: Bill Tubbs 2021년 6월 18일
I think this is an undesirable feature of the waterfall plot function and I'm posting it here so that others don't spend as long as I did trying to figure out why your plot doesn't look right.
Here is an example of a correcly rendered waterfall plot:
[X,Y] = meshgrid(-5:.5:5);
Z = Y.*sin(X) - X.*cos(Y);
p = waterfall(X,Y,Z)
If you happen to have nan values in your data the plot does not raise an error but the white 'area-fill' of each plot line dissappears.
Z(:,5) = nan;
p2 = waterfall(X,Y,Z)
I couldn't find any mention of this in the documentation, and when you don't know that nan values are the cause of this, it's very hard to diagnose. Especially if your data set is large or the nan values are in the first or last column and it's not so obvious to see that there is a gap in the data as it is in these simple examples.
  댓글 수: 3
Bill Tubbs
Bill Tubbs 2021년 6월 18일
I just checked and a regular area plot exhibits the behaviour I was suggesting for solution #2:
x = -5:.5:5;
y = sin(x)+2;
area(x, y)
grid on
y(x == 0) = nan;
area(x, y)
grid on

댓글을 달려면 로그인하십시오.





Community Treasure Hunt

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

Start Hunting!

Translated by