Surround color for display
조회 수: 5 (최근 30일)
이전 댓글 표시
When I create a display using pcolor of data that is contained within a circle I insert NaN values in all locations not within the circle and then the display creates white areas where the NaNs are located. Is there any way I can get this same effect but have the surround black instead of whiite?
댓글 수: 0
채택된 답변
DGM
2022년 6월 17일
편집: DGM
2022년 6월 18일
When you mask off data using NaN, the plot is simply not drawn there, revealing whatever graphics objects might be beneath it. If there aren't other objects beneath it in the axes, the color that's shown in that region is the axes background color, and is independent of the colormap that's in use. Just set the color of the axes to whatever color you want.
numpoints = [1000 1000]; % [x y]
% build boundary curve
x = linspace(-2,2,numpoints(1));
y = 4*x-x.^3;
% build 2D map
y2 = linspace(-4,4,numpoints(2)).';
z = sin(x*2).*sin(y2*2);
% set unwanted map data to NaN
z(y2>y) = NaN;
% plot it
pcolor(x,y2,z)
colormap(parula)
shading flat
set(gca,'color','m') % magenta
% or maybe a different color
figure
pcolor(x,y2,z)
colormap(parula)
shading flat
set(gca,'color','k') % black
댓글 수: 6
Image Analyst
2022년 6월 19일
Think of an axes having, or being able to have, a bunch of images on top of each other in a stack. Each image is a layer. If you've ever used Photoshop you're familiar with layers where images are stacked on top of each other vertically. And you can specify the order of the layers (what's on top of what). It's like that.
DGM
2022년 6월 19일
편집: DGM
2022년 6월 19일
What @Image Analyst said is basically the analogy I'd give. Objects in the figure window are ultimately reduced to raster images that are composited just as you might combine transparent images in an image manipulation environment or how one might stack multiple cels in traditional animation.
As far as how to tell what's in the "stack", that's kind of hard to say. On one hand, you can look at the 'children' property of the axes or figure to see what objects are there, but it might not always be clear whether those objects are relevant to the discussion. For example, it's possible to position objects (e.g. text objects) outside the extent of their parent axes. While it's possible that objects within the axes can be made invisible, certain visible objects may have their handles hidden, preventing them from showing up when checking the descendants of their assumed parent.
As confusing as that sounds, it's usually pretty straightforward. There are usually only a few major objects in the axes, and you'll know what they are because you wrote the code. Their stacking order is usually apparent based on the order they were created. The stacking order of an object can be manipulated with uistack().
추가 답변 (1개)
Image Analyst
2022년 6월 15일
Why not just write 0's to those pixels instead of NaNs?
댓글 수: 4
Image Analyst
2022년 6월 17일
I did think of that, or something like that. It really doesn't matter if the matrix values represent an intensity like a regular gray scale image or a height or elevation. I was thinking values were brightness but they just as well could have been elevation. That's why I suggested using a colormap and it looks like you found a working solution using that. You should also look at the function clim (r2022a or later) or caxis (r2021b or earlier).
But @DGM presented an alternative way and it looks like you preferred that way since you accepted the answer.
참고 항목
카테고리
Help Center 및 File Exchange에서 Graphics Object Properties에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!