Question about patches after mapshow, and colorbar with mapshow

조회 수: 7 (최근 30일)
David McVea
David McVea 2020년 1월 7일
답변: Raunak Gupta 2020년 1월 21일
Hello,
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.
patch(S(1).X,S(2).Y,'r')
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!

답변 (1개)

Raunak Gupta
Raunak Gupta 2020년 1월 21일
Hi,
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.
colormap(colorgradient);
Hope this resolves the issue.

카테고리

Help CenterFile Exchange에서 Green에 대해 자세히 알아보기

제품


릴리스

R2015b

Community Treasure Hunt

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

Start Hunting!

Translated by