MATLAB Answers

Mapping Toolbox: Eigenvector specifies Color of shape file

11 views (last 30 days)
I want to plot countries including their borders in Europe and then set the color of each country according to a number. Currently I am able to generate a map consisting of about 50 country shape files. Now, I want to change the Facecolor of each shape file according to the value of an eigenvector. My problem is that there is only one 'number' per country, so I cannot generate a color code ?
My idea is to have each number correspond to a color (like the colormap jet). Large values would correspond to a darker red, small values to a darker blue etc... How can I do this ?
In the end, I will generate a couple of maps, so I do not want the colors to vary for each map. A map colored completely green should have smaller eigenvector values than a map colored completely red. I am aware of the command 'caxis', but not sure how I can set a colormap to specify the colors used in my maps.

Accepted Answer

Kelly Kearney
Kelly Kearney on 16 May 2017
The easiest way to do this with complex polygons (multi-face polygons or polygons with holes, as is often the case with borders) in a mapping axis is to use the admittedly very unintuitive makesymbolspec function combined with mapshow or geoshow. The makesymbolspec function allows you to build a colormap with specified limits, and color the plotted polygons based on an attribute in the shapefile. (You can easily add additional attributes to the geostruct object if your eigenvalues are calculated independently rather than stored in the shapefile):
Usa = shaperead('usastatehi.shp', 'usegeocoords', true);
colorrange = makesymbolspec('Polygon', {'LabelLat', [20 65], 'facecolor', jet(64)});
geoshow(Usa, 'SymbolSpec', colorrange);
Note that this sets each polygon face color to an rgb triplet, and this value is not actually linked to the mapping axis's colormap. So if you want to add a colorbar, you need to sync that to your spec:
set(gca, 'clim', [20 65]);

More Answers (0)

Community Treasure Hunt

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

Start Hunting!