Surf and NaN plotting bug

조회 수: 11 (최근 30일)
James Noll
James Noll 2019년 10월 9일
댓글: Walter Roberson 2019년 10월 10일
Hello,
I have some data I am trying to plot with the surf command. The data has many NaN entries with small islands/peninsulas of good data. The NaN entries represent time/locations where no data is available. When I plot the data using surf(), I lose many of the finer feature - thin islands disappear. If I replace all of the NaN entries with a scalar (0), the islands reappear. Is there a workaround to plot all of the good data and have the NaN remain as blanks?
Matlab version is 2017a

답변 (2개)

James Noll
James Noll 2019년 10월 10일
편집: James Noll 2019년 10월 10일
Thank you for the information! I did not realize that each facet color was driven by the value of the neighboring facets when using surf(). Since I am only interested in the 2D view of the data, it turns out pcolor() has the functionality I need. It does not interpolate by default, so the data islands surrounded by 'nan' are no longer being blanked.
I don't have the toolbox required for warp(), so I was not able to check that as a possible solution. Below is an example output for some test data with nan's randomly distributed.
x = [1:1:100]'; y = [1:1:100]'; b = rand(size(x,1), size(y,1));
b(b<.3) = nan;
figure; surf(x,y,b); view(2); title('surf');
figure; pcolor(x,y,b); title('pcolor');
  댓글 수: 1
Walter Roberson
Walter Roberson 2019년 10월 10일
pcolor() uses the x and y you give, and all zeros as the z, and uses the data you give as the cdata information in a call to surface() . Which is to say, it is surf() with x, y, 0, b . If you look at something like
pcolor(randi(10,5,7))
you will see that it draws (5-1) by (7-1) faces. It is doing interpolation.

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


Walter Roberson
Walter Roberson 2019년 10월 10일
편집: Walter Roberson 2019년 10월 10일
surf() and pcolor() determine the color of faces by bilinear interpolation of the four corners. Any single nan is at the corner of four different faces, so any given nan "poisons" four faces making them empty because the calculation comes out nan. It is easy for thin islands to disappear.
You should look more carefully at the CData and AlphaData properties
However when you make your decisions you are probably going to encounter the same basic issue that surf faces do not reflect individual locations, which is probably what you want.
Depending on your needs, warp() might be more useful to you. If not, then go for patch() as it offers more flexibility as to how face color is derived.

카테고리

Help CenterFile Exchange에서 Lighting, Transparency, and Shading에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by