How do I set a fixed color scheme for pcolor?

72 views (last 30 days)
I'm making a graph of measurements, and pcolor is a very good way to display these data, but everytime the data is slightly different, the color scheme changes, which is annoying. I've tried some solutions with CData, but my inexperience has left me frustrated and with no solution when I try to extrapolate how to use CData based on other people's questions.
Basically, I want the colors to be the same every time in terms of order, not number, (.0143in can't always be blue, but blue always has to be the largest number).
Any help would be great. Here's my current code for the graph:
"figure
pcolor(postnomtable)
colorbar"
where postnomtable is an m by m matrix
  1 Comment
Sebastian Holmqvist
Sebastian Holmqvist on 10 Jul 2012
I'm not sure why you get different ordering of colors in your plots (I don't). The default colorscheme ('jet') is normally auto-scaled to have the highest number as red and the lowest as blue. The value right in between is somewhere around greenish.
You can use caxis([cmin cmax]) so specify your limits (everything outside of those limits gets the outermost color).
You can also use colormap('default') to set the current colorscheme as the default one for all future plots.

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 10 Jul 2012
Edited: Image Analyst on 11 Jul 2012
You do know that the colors depend not on the value of a particular element, but on the slope of a plane fitted between the 4 elements at the corner, don't you? Did you see this in the help: "With shading interp, each cell is colored by bilinear interpolation of the colors at its four vertices, using all elements of C." And you know that you're "missing" the last row and column because you read this: "The last row and column of C are not used" What is the exact call to pcolor that you used? Then, explain to me why you want to use pcolor() instead of imshow() or image().
Anyway, if you want blue to be the largest value, just flip jet. See this demo:
m = randi(3, [5 5])
pcolor(m)
flippedJetColorMap = flipud(jet(256));
colormap(flippedJetColorMap);
colorbar
Whoa! Wait a minute! Did you notice that all the 1's don't have the same color, and all the 2's don't have the same color, and that all the 3's don't have the same color? And did you notice that there are only 4 by 4 cells displayed, not 5 by 5 like the size of my "m" matrix? That doesn't seem intuitive! Now you know why I don't recommend pcolor. But at least the colormap is flipped like you want, though it doesn't really apply to anything.
  6 Comments
Andrew
Andrew on 11 Jul 2012
That code did exactly what I was thinking of. Good job. Thanks.
"Undefined function or method 'imtool' for input arguments of type 'char'.
Error in ==> DemoForGreenScale at 5 imtool close all; % Close all imtool figures."
I don't need that code though. The one you just posted works great.
Image Analyst
Image Analyst on 11 Jul 2012
Strange. imtool is included in the Image Processing Toolbox, which I guess you must not have. If you took out that line, then you would have hit the line saying you don't have the Image Processing Toolbox installed. If you took that out also, then it would have complained about imshow(). But you could have fixed that by using image() instead of imshow(). Anyway, glad it's working for you.

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!