Set Polygon FaceColor to 'none' after coloring it using mapshow

31 次查看(过去 30 天)
Hi,Im having trouble with FaceColor using map show.
I'm loading a shapefile and plot it using mapshow with no fill.
after wards, I want to color some of the polygon's red (let's say it polygons No. 1,3 &5).
B = shaperead('Sub_basins.shp');
mapshow(B,'FaceColor','none');
mapshow(B([1 5 6]),'FaceColor', 'r')
later on, I want to erase the color from some of them (let's say No. 1):
mapshow(B(1),'FaceColor', 'none')
But for some reason, the polygon stays red.
Did anyone have a solution for this?
I'm attaching the .shp file if it helps.
Thanks!
Amit

采纳的回答

Ritish Sehgal
Ritish Sehgal 2023-1-24
Hi,
You can try setting the ‘FaceColor’ attribute to white color to remove the red color of the Polygon.
For example, the below command will whiten the 1st Polygon.
mapshow(B(1), 'FaceColor', 'w')
Hope it helps!!
  2 个评论
Ritish Sehgal
Ritish Sehgal 2023-1-31
Hi,
It is an expected behavior in “mapshow” function. This function adds polygon objects to the same figure handle without removing any preceding polygon object. It is similar to using “hold on” for an ‘axes’ object to plot multiple datasets.
When you set the polygon FaceColor to ‘none’ in the third call to “mapshow” function it adds a polygon with FaceColor = ‘none’ on top of the polygon which already exists (i.e. polygon with FaceColor = ‘r’) and hence not affecting the displayed figure.
You can access the polygon objects and update their properties using the output argument of “mapshow” function. So, the commands can be re-written in the following way:
B = shaperead('Sub_basins.shp');
ms = mapshow(B, "FaceColor", "none");
set([ms.Children([1,5,6])], "FaceColor", "r")
set(ms.Children(1), "FaceColor", "none")
Hope it helps!!

请先登录,再进行评论。

更多回答(0 个)

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by