MATLAB Answers

Question about patches after mapshow, and colorbar with mapshow

13 views (last 30 days)
David McVea
David McVea on 7 Jan 2020
Answered: Raunak Gupta on 21 Jan 2020
I am trying to create a chloropleth map, with shapes coloured according to a field of the shapefile. Some regions, due to incomplete data, should have a neutral colour.
I have defined a symbol specification structure
ratioColor = makesymbolspec('Polygon' {'Ratio',[0.5 1.5],'FaceColor', colorgradient}
Seems to work fine to draw the map.
However if I then try to draw patches on top of the regions that should have a neutral color, I get nothing.
For example gives nothing.
Also, set the properties of the patch (facecolor) using set does nothing.
Second and I think related issue is that if I add a colorbar to the map, It doesn't refelct the values on the map. From my symbolspec, I think the colormap should map everyting below 0.5 to the lowest value and above 1.5 to the highest, and grade everyting in between. I am not sure it is doing this and the colorbar shows 0 - 1 as the limits.
Any help is apprecaited, thanks!


Sign in to comment.

Answers (1)

Raunak Gupta
Raunak Gupta on 21 Jan 2020
As per my understanding the incomplete data that is present is replaced by NaN (Not a number) that is the main issue while assigning the FacelColor in case of Patch. You may want to replace the NaN values with closest value in corresponding row in S(1).X and S(2).Y so that the patch become a close figure. With NaNs the patch won’t be able to assign FaceColor.
For the second part in makesymbolspec, The number of colors that will appear depends upon the size of colorgradient matrix. So, if colorgradient is m x 3 then the range that is mentioned in value of ‘Ratio’ will be split uniformly in m buckets.
For colorbar query I think you may try setting the colormap to the colrgradient that will provide the color mapping for the colorbar otherwise it is set to the default which is parula. For setting the colorbar put the following command before adding the colorbar. This will surely map the range as required.
Hope this resolves the issue.


Sign in to comment.

Sign in to answer this question.




Translated by