A mysterious problem regarding NaNs, imagesc and subplots.

3 ビュー (過去 30 日間)
Alec Nagel
Alec Nagel 2011 年 6 月 13 日
Hi,
I am working on a project where I need to plot an error rate as a function of two parameters as both surface and imagesc. Since I do not have results for all combinations of the parameters, my matrix of error rates contains quite a few NaNs. I need to distinguish the NaNs from the zeros, and found a neat method at the end of this thread for omitting them from the imagesc plot:
h=imagesc(A);
set(h,'alphadata',~isnan(A))
This worked like a charm at first, but then I needed to change the axis on the surface plot (which is in a separate subplot in the same figure) to a log scale, and suddenly the NaNs in the imagesc plot pop back up. See for yourself:
% Initialize error matrix A with random values, and some NaNs.
A = rand(10,10);
A(A<1/3) = NaN;
% Here the NaNs show up as white
figure
subplot(1,2,1);
surf(A)
subplot(1,2,2);
h=imagesc(A);
set(h,'alphadata',~isnan(A))
% Here they don't
figure
subplot(1,2,1);
surf(A)
set(gca,'XScale','log');
subplot(1,2,2);
% set(gca,'XScale','linear'); % I tried this to no avail.
h=imagesc(A);
set(h,'alphadata',~isnan(A))
I have no idea why this happens! Why would the axis scale on one subplot influence the other?
Is this a bug in Matlab, or am I doing something wrong here?
Any input would be much appreciated.

採用された回答

Doug Hull
Doug Hull 2011 年 6 月 13 日
There are three renderers in MATLAB. The only one that handles transparency is OPENGL. Unfortunately, OPENGL does not handle log scale.
  3 件のコメント
Walter Roberson
Walter Roberson 2011 年 6 月 13 日
There is only one renderer per _figure_.
Alec Nagel
Alec Nagel 2011 年 6 月 13 日
Ah. I see then. Thanks.

サインインしてコメントする。

その他の回答 (2 件)

Richard
Richard 2011 年 6 月 14 日
A workaround is to use a surface with flat shading (the default) and just view it from above. You do have to do a bit of extra work to get a similar output as imagesc gives you.
% Initialize error matrix A with random values, and some NaNs.
A = rand(10,10);
A(A<1/3) = NaN;
% Here the NaNs show up as white
figure
subplot(1,2,1);
surf(A)
subplot(1,2,2);
surf(0.5:(size(A, 2)+0.5), 0.5:(size(A, 1)+0.5), ...
zeros(size(A)+1), A, 'edgecolor', 'none');
axis('tight');
view(2);
grid('off');
box('on');
set(gca, 'YDir', 'reverse');
  1 件のコメント
Alec Nagel
Alec Nagel 2011 年 6 月 14 日
Thanks! That is a good suggestion.

サインインしてコメントする。


Jordan Mertes
Jordan Mertes 2011 年 6 月 22 日
I'm having a similar problem. I turn my NaN to transparent but when I do this the left and bottom axis box disappear. I can't figure out how to get them back. I have tried with the other renderers but one of them makes the NaNs blue again and the other doesn't do anything. Any thoughts on this?
Thanks

カテゴリ

Help Center および File ExchangeGraphics Performance についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by