How to change the color map manually.

14 次查看(过去 30 天)
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

采纳的回答

Walter Roberson
Walter Roberson 2018-6-21
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 个评论
Jotheeshwar V
Jotheeshwar V 2018-6-23
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 2018-6-23
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

请先登录,再进行评论。

更多回答(1 个)

Jotheeshwar V
Jotheeshwar V 2018-6-22
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

类别

Help CenterFile Exchange 中查找有关 Colormaps 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by