How can I change the color of a map given shapefile and values?
26 次查看(过去 30 天)
显示 更早的评论
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/152410/image.png)
All the best.
0 个评论
回答(2 个)
Nitin Khola
2015-7-24
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:
0 个评论
Navid Ghajarnia
2022-1-20
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...
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Lighting, Transparency, and Shading 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!