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?

采纳的回答

DGM
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
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
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
Image Analyst 2022-6-15
Why not just write 0's to those pixels instead of NaNs?
  4 个评论
Charles Campbell
Charles Campbell 2022-6-17
Consider the fact that the height in a surface, referenced to a given point which could be the center of the surface, with have values above and below this value. Perhaps you have not thought of this. In the meantime I have found a solution which involves creating a colormap with black as the most negative value and creating a spacing vector for a contourf map that has the lowest value just one increment less than the most negative value of data. I then add a mask to the data with 0's where the data actually exits and at other location in the mesh value one increment below the most negative data value. This will then create the desired black surround and preserve the colored contourf map where there is real data.
Image Analyst
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 CenterFile Exchange 中查找有关 Graphics Object Properties 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by