Reputation: 512
How can I change the color of the borders of polygons in a choropleth map in MatLab? (While keeping at the same time the colors inside the polygons). Reproducible code below.
MapLatLimit = [41 48];
MapLonLimit = [-74 -66];
NEstates = shaperead('usastatelo', 'UseGeoCoords', true, 'BoundingBox', [MapLonLimit' MapLatLimit']);
datawithNaN = [30 20 30 NaN 40 50 NaN NaN];
% Here replace NaNs with a number (treat as category):
datawithNaN(isnan(datawithNaN)) = 0;
datawithNaN = num2cell(datawithNaN);
% Here I create a color map, using white for NaN (category = 0);
mycolormap = [ 1 1 1;...
.4 .1 .9;...
.3 .2 .8;...
.2 .3 .7;...
.1 .4 .6];
[NEstates.datawithNaN] = deal(datawithNaN{:});
densityColors = makesymbolspec('Polygon', {'datawithNaN', [0 50], 'FaceColor', mycolormap});
mapshow(NEstates, 'DisplayType', 'polygon', 'SymbolSpec', densityColors)
Upvotes: 1
Views: 423
Reputation: 4757
By adding the property 'EdgeColor'
you can change the colour to any colour. In the example below I selected the colour red, r
. For more colour options: MATLAB Documentation: ColorSpec (Color Specification). The colour can also be defined as an RGB triplet matrix in the form of an array [r g b]
:
Where,
r
→ Red intensity ranging from 0 to 1.
g
→ Green intensity ranging from 0 to 1.
b
→ Blue intensity ranging from 0 to 1.
densityColors = makesymbolspec('Polygon', {'datawithNaN', [0 50], 'FaceColor', mycolormap,'EdgeColor','r'});
Upvotes: 1