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

조회 수: 28 (최근 30일)
Amit Kallush
Amit Kallush 2023년 1월 23일
댓글: Ritish Sehgal 2023년 1월 31일
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
Amit Kallush
Amit Kallush 2023년 1월 24일
Thanks it works!
wonder why 'none' isn't working..
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