pcolor
显示 更早的评论
How to get rid of the black lines at the edge of each changing color?
6 个评论
Image Analyst
2011-11-16
I'm curious why you're using pcolor() at all. Tell me why you're using that, which has one less "pixel" in each direction than the array you're trying to display, instead of the more conventional imshow(), image(), or imagesc(). I've not been able to figure out or hear why anyone would want to use that to display a 2D array, such as one that represents an image.
Arundhatee Talukdar
2011-11-16
Here's an illustration for you. Run this code:
m =[...
2 3 3 1
2 2 1 1
3 3 3 1
2 1 3 3] % Define a 4x4 matrix
pcolor(m) % Shows 3x3, not 4x4 as most people would expect.
colorbar
Now, how many elements do you see? Were you expecting to see 4 by 4? Were you expecting to see that every "1" had the same color, every "2" had the same color, and every "3" had the same color? If your answers are yes, then you can see that it doesn't give you what you were expecting at all, and you should learn how to use imshow() - it's really not that hard, it's not. You don't have to use most of the optional input arguments.
imshow(m, [], 'InitialMagnification', 3000);
axis('on', 'image'); xticks(1:4); yticks(1:4);
colormap(parula(3))
colorbar
The image above has 4 by 4 pixels/blocks as expected, and the brightnesses of the pixels correspond to the values in the 4x4 m matrix.
Kelly Kearney
2011-11-16
@Image Analyst: Pcolor is much more useful than imagesc when your data array isn't one that represents an image, e.g. a dataset on an uneven or non-rectilinear grid. Also, why do you imply that in the example above identical data values would be mapped to different colors with pcolor? The dropped-edge cell, I concede, is a little annoying, though I usually circumvent that with NaN-padding.
Walter Roberson
2011-11-16
Kelly, pcolor does color interpretation for the faces according to the colors of the vertices (which are not drawn), so the color of any one face is not directly associated with a single point value and instead is an interpolation according to what is nearby.
Kelly Kearney
2011-11-16
That's true only if the shading scheme is set to interpolated. Otherwise, the color is associated with a single vertex, and in Image Analyst's example, each cell with a 1 in its upper right corner is indeed the same color as other 1-cells, regardless of its neighbors.
回答(2 个)
Jonathan
2011-11-16
hand = pcolor(hadamard(20))
set(hand, 'linestyle', 'none')
3 个评论
Fangjun Jiang
2011-11-16
Interesting hadamard() function!
Arundhatee Talukdar
2011-11-16
Jonathan
2011-11-16
hand = pcolor(X,Y, Z)
set(hand, 'linestyle', 'none')
Kelly Kearney
2011-11-16
Alternatively
pcolor(X,Y,Z);
shading flat;
类别
在 帮助中心 和 File Exchange 中查找有关 Creating, Deleting, and Querying Graphics Objects 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

