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

 Réponse acceptée

Walter Roberson
Walter Roberson le 21 Juin 2018

1 vote

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 commentaires

I just examined the case of passing in three numeric arguments, like you have. It appears that in that case, geoshow looks at the third argument (which you named Y but which is in the position that would be used for Z coordinates). If the third argument is a 2D array, then geoshow() automatically makes it grayscale by copying the data to all three RGB planes using repmat() with [1,1,3]). That RGB array is then used internally to create a texturemapped surface() object. Because it is RGB, it is not affected by changing the colormap.
What you will need to do is create an already-colored version of the data. You could do something like
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);
However... I would suggest to you that you instead consider a completely different approach:
warp(Z_grid, X_grid, Y);
followed by your appropriate colormap() call.
Images displayed with warp() are affected by colormap changes.
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?
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

Connectez-vous pour commenter.

Plus de réponses (1)

Jotheeshwar V
Jotheeshwar V le 22 Juin 2018

0 votes

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

Catégories

En savoir plus sur Color and Styling dans Centre d'aide et File Exchange

Produits

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by