Bottom and left edges of pcolor plot?

51 views (last 30 days)
John
John on 3 Mar 2013
Edited: Adrian on 13 Aug 2019
When I use pcolor to plot a colored surface based on values in a matrix, both the lower and right edge of the box around the axes do not show. I have tried different shading calls, turning the box on, and setting the layer to top. This happens in both R2012a with Mac OS and R2012b with Windows 7. What options are there for making those missing edges show up? Code that reproduces the problem is as follows:
C = rand(20) ;
pcolor(C)
shading interp
box on
set(gca,'Layer','top')

Answers (3)

Image Analyst
Image Analyst on 4 Mar 2013
That's what I've been telling unsuspecting people for years. It chops off a row and column. Unless you know that you need, really need, pcolor(), don't use it. Use image() or imshow() instead. I don't even like imagesc() because it applies some arbitrary colormap by default that is almost never helpful.
  4 Comments
Image Analyst
Image Analyst on 2 Oct 2018
I didn't even understand his comment at all. I was just stating that if you use pcolor() to display an image, such as the poster's 20x20 "C" array, it will not show the lower and right edge of the array, as the poster stated, and you could use image() or imshow() to get that last row and column to show up.
C = rand(20);
subplot(1, 2, 1);
props = pcolor(C)
shading flat
box on
axis('on', 'image');
set(gca,'Layer','top')
title('pcolor() shows 19 columns', 'FontSize', 20);
subplot(1, 2, 2);
imshow(C);
axis('on', 'image');
title('imshow() shows 20 columns', 'FontSize', 20);
This is because the value for pcolor is shown at the edges of the pixels, not over the whole pixel like imshow(). But if you're looking at the whole image like the colored blocks were pixels, you're going to be missing one. imshow() displays it like there is a pixel block centered at the index as shown in the figure above, so you see all the pixels.
Neither me nor the poster was talking anything about X, Y, or Z, scaling, stretching, or color accuracy. Even if I were passing in X or Y to imshow() to get the tick marks to show up in calibrated units, I don't see why anyone would pass in an X or Y with non-monotonic values. That seems crazy. Why would you want X to ever go in reverse for part of the way with your image?
Adrian
Adrian on 13 Aug 2019
Edited: Adrian on 13 Aug 2019
Agree with Orion. Non-monotonic also means increasing in uneven steps and that is more common than you may think. If that is the case do NOT use image() or imagesc(), you would just be fooling youself as these functions only care about the first and last values to be used as limits, distributing the in-between pixels evenly, regardless if that's the case or not.

Sign in to comment.


Walter Roberson
Walter Roberson on 4 Mar 2013
Edited: Chad Greene on 2 Oct 2018
When you use shading interp, each cell's color results from a bilinear interpolation of the colors at its four vertices.
Now consider that if you had a 2x2 array of data, there would only be one place that had four vertices: the point at which the four pixels meet. One location, one drawn cell. N x M locations, (N-1) x (M-1) drawn cells.

Chad Greene
Chad Greene on 1 May 2015
Here's an example of the funny things pcolor, surf, and imagesc can do to your data.

Tags

Products

Community Treasure Hunt

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

Start Hunting!