I see a bug in pcolor

1 view (last 30 days)
Mark Mendlovitz
Mark Mendlovitz on 21 Oct 2022
Commented: Steven Lord on 22 Oct 2022
C = eye(10);
pcolor(C)
colormap summer
This example, which comes straight out of the documentation, produces a 9 x 9 colored block matrix, not a 10 x 10 matrix. This is a bug.

Accepted Answer

Image Analyst
Image Analyst on 21 Oct 2022
It's not a bug - it's a feature. That's why I never use pcolor. I use imshow instead, which shows every pixel.
m = magic(3) % Create a 3-by-3 matrix
m = 3×3
8 1 6 3 5 7 4 9 2
subplot(2, 1, 1);
pcolor(m)
title('pcolor');
subplot(2, 1, 2)
imshow(m, []);
title('imshow');
Note that pcolor has the vertices (where the black lines are) be the value of the pixel, not the value of the tiles.
I suggest that you use imshow or image or imagesc, with the colormap option if you want a colormap.
  3 Comments
Mark Mendlovitz
Mark Mendlovitz on 22 Oct 2022
I'm still not clear how the entries of a 10 x 10 matrix would correspond to a 9 x 9 plot of vertices. Maybe you mean edges? Still, I can think of beter ways to plot a graph. Regardless, I'll use imshow instead.
Steven Lord
Steven Lord on 22 Oct 2022
As another analogy, this time in 1 dimension: it's the fence post versus fence rail problem. If you want to create a fence with two segments you need three posts, with the first rail segment being between posts 1 and 2 and the second between posts 2 and 3. The image-related functions let you say what color the rails are. The pcolor function lets you specify the color of the posts and colors the rails with the color of the post where they start. The color of the last post (or the last row/column in the pcolor case) doesn't affect the color of any rail.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!