How can I change the color of a map given shapefile and values?

20 visualizaciones (últimos 30 días)
Emanuele Massaro
Emanuele Massaro el 22 de Jul. de 2015
Respondida: Navid Ghajarnia el 20 de En. de 2022
Hello, I would like to generate a map from shapefiles given where for each provinces I have a specific value. Let say I have 52 provinces, so I have an array of 52 different values. What I am doing now is to generate a loop:
for i = 1:52
col_=cols(I(s),:);
mapshow(obj.shapes(s),'FaceColor',col_);
end
How can I generate "I" and have a colorbar that indicates the real values? Now I am able to generate something like this but it is not what I want.
All the best.

Respuestas (2)

Nitin Khola
Nitin Khola el 24 de Jul. de 2015
As per my understanding, you wish to change the 'FaceColor' of polygons depicting provinces, as per some particular data values, which can be displayed using "mapshow" or "geoshow". Further, I understand that you are importing a shapefile containing the necessary information.
One of the possible methods to do this is by making a rule for the 'Polygon' geometry using " makesymbolspec " function.
A step by step procedure to do it is described in the following example:
The sections most relevant to you are:
Create an autumn colormap for the six New England states, and then use the flipud command to invert the matrix.
fall = flipud(autumn(numel(NEstates)));
Make a symbol specification structure, a symbolspec , that assigns an autumn color to each polygon according to the population density.
densityColors = makesymbolspec('Polygon', {'PopDens2000', ...
[0 maxdensity], 'FaceColor', fall});
This example creates an "autumn" colormap to display population density data. However, as stated in the example, you can experiment with other colormaps as well. You can also create a custom colormap.
For more information on using colorbars and colormaps in regard to representing geographic variables on maps, refer to the following documentation:

Navid Ghajarnia
Navid Ghajarnia el 20 de En. de 2022
As far as I understood, you can't do it in an easy way. But there is a way around it:
Lets imagine you want the hot colormap and you want 256 colors in it. so 1st step:
cmap = hot(256);
Then, lets imagin your data based on which you want to give color to your polygons is between 1 to 150. This means that if your province's value is one, then cmap(1,:) is your color and if your province's data is 150 then cmpa(256,:) gives you the final color in hot colormap. This means that with the command below you can get colors in a relatively continous way for each of your provinces:
color_row = round(Data/150 * 256);
cc = cmap(color_row,:);
Then by having the color code (cc) you can use mapshow and map your polygon and give the correct color to it.
Hope it helps...

Categorías

Más información sobre Lighting, Transparency, and Shading en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by