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

28 views (last 30 days)
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

Accepted Answer

Ritish Sehgal
Ritish Sehgal on 24 Jan 2023
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 Comments
Ritish Sehgal
Ritish Sehgal on 31 Jan 2023
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!!

Sign in to comment.

More Answers (0)

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!