Clear Filters
Clear Filters

How to change the color map manually.

7 views (last 30 days)
I have tried changing the colourmap in the Figures interface.
The change has been reflected only in the legend bar, not in the plot.
I am plotting grid plot along X (2634x1) and Z (512x1) axes with series of Y (512x2634) values which has to be plotted in colour map.
The Code follows.
>> load X.txt
>> load Y.txt
>> load Z.txt
>> [Z_grid, X_grid] = ndgrid(Z, X);
>> geoshow(Z_grid, X_grid, Y);
After this, the figure Dialog box pops up.
In that, I have tried to change the colourmap using menu. but, the changes are not reflected in the plot.
Kindly, help me out of this.
Regards,
Jotheeshwar Velayudham

Accepted Answer

Walter Roberson
Walter Roberson on 21 Jun 2018
geoshow() and mapshow() appear to invoke the internal function mappolygon() (at least for some geometries.)
mappolygon() creates patches that have [1 1 0.5] hard-coded as the default face color.
That is, at least for some kinds of input, the patches that are created have RGB face colors and therefore are not affected by changes to the colormap.
To change the color of faces, you need to create a symbolize structure and pass it in, specifying the color for each type of item.
  3 Comments
Jotheeshwar V
Jotheeshwar V on 23 Jun 2018
edges = [-1 -1/2 -1/10 0 1/10 1/2 1];
nedge = length(edges);
fwdidx = 1:floor(nedge/2);
cmap = [0 0 1;
1/3 1/3 1;
2/3 2/3 1;
1 1 1;
1 2/3 2/3;
1 1/3 1/3;
1 0 0];
[~, bin] = histc(Y, edges);
Y_rgb = ind2rgb(bin, cmap);
geoshow(Z_grid, X_grid, Y_rgb);
This code was working on my friend's laptop.
Now, I have reinstalled my software and it worked.
But, the problem now is,
when I a displaying legend, it is not showing the corresponding colour pattern.
Can you tell me the code to plot the graph with legend displayed?
Walter Roberson
Walter Roberson on 23 Jun 2018
geoshow() creates one graphics object. legend only creates one entry for each graphics object.
The trick is to use something like,
state_names = {'very bad', 'kinda bad', 'not so good', 'okay', 'good', 'better', 'best'};
hold on
h = arrayfun(@(idx) plot(nan, nan, 'Color', cmap(idx, :), 'DisplayName', state_names{idx}), 1:length(state_names));
legend(h, 'show');
hold off

Sign in to comment.

More Answers (1)

Jotheeshwar V
Jotheeshwar V on 22 Jun 2018
I got the point you were about to say. Since, I am a beginner, I don't know how to create symbolize structure.
Kindly mention code for this work.
Presently, In z-axis, it is considered that -1 is negative extreme and +1 is positive extreme, The plot is like, -1 is assigned with white and +1 is assigned with black.
Here, 0 is my study interest which is denoted in grey. Since grey has many shades, it is very difficult for me to differentiate with actual zero value and adjacent values.
In need like -1 to be assigned with blue, +1 to be assigned with red and zero to be assigned with white
Kindly, help me out of this by providing code or sample code for this case.
Regards,
Jotheeshwar Velayudham

Categories

Find more on Colormaps in Help Center and File Exchange

Tags

Products

Community Treasure Hunt

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

Start Hunting!