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

28 visualizaciones (últimos 30 días)
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

Respuesta aceptada

Ritish Sehgal
Ritish Sehgal el 24 de En. de 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 comentarios
Amit Kallush
Amit Kallush el 24 de En. de 2023
Thanks it works!
wonder why 'none' isn't working..
Ritish Sehgal
Ritish Sehgal el 31 de En. de 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!!

Iniciar sesión para comentar.

Más respuestas (0)

Productos


Versión

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by