44
55import cartopy .crs as ccrs
66import matplotlib .pyplot as plt
7- from shapely .geometry import MultiLineString
7+ from shapely .geometry import MultiLineString , MultiPolygon , Polygon , shape
88
99from gwspy import PlateModel
1010
@@ -25,30 +25,81 @@ def main(show=True):
2525 # plot polygon without edges first
2626 # and then get the polygon edges as lines and plot the edges
2727 # this is to get rid of the vertical line along the dateline
28- polygons = topology_10 .get_plate_polygons (return_format = "shapely" )
29- lines = topology_10 .get_plate_polygons (return_format = "shapely" , as_lines = True )
28+ _polygons = topology_10 .get_plate_polygons ()
29+ _lines = topology_10 .get_plate_polygons (as_lines = True )
30+
31+ # print(_polygons)
32+
33+ polygons = []
34+ for feature in _polygons ["features" ]:
35+ # if feature["properties"]["type"] != "gpml:TopologicalClosedPlateBoundary":
36+ # continue
37+ s = shape (feature ["geometry" ])
38+ if isinstance (s , Polygon ) or isinstance (s , MultiPolygon ):
39+ polygons .append (s .buffer (0 ))
40+
41+ lines = []
42+ colors = []
43+ feature_types = []
44+ for feature in _lines ["features" ]:
45+ s = shape (feature ["geometry" ])
46+ lines .append (s )
47+ f_type = feature ["properties" ]["type" ]
48+ if f_type == "gpml:TopologicalNetwork" :
49+ colors .append ("green" )
50+ elif f_type == "gpml:TopologicalClosedPlateBoundary" :
51+ colors .append ("blue" )
52+ elif f_type == "gpml:TopologicalSlabBoundary" :
53+ colors .append ("yellow" )
54+ elif f_type == "gpml:OceanicCrust" :
55+ colors .append ("orange" )
56+ else :
57+ colors .append ("red" )
58+
59+ feature_types .append (f_type )
60+
61+ print (set (feature_types ))
3062
3163 fig = plt .figure (figsize = (12 , 6 ), dpi = 120 )
3264 ax = plt .axes (projection = ccrs .Robinson ())
3365
3466 ax .set_global ()
3567 ax .gridlines ()
3668
69+ # fill the polygons with grey
3770 ax .add_geometries (
3871 polygons ,
3972 crs = ccrs .PlateCarree (),
40- facecolor = "lightgrey " ,
73+ facecolor = "grey " ,
4174 edgecolor = "none" ,
4275 alpha = 0.5 ,
4376 )
4477
45- for line in lines :
78+ # plot the lines
79+ for line , c , t in zip (lines , colors , feature_types ):
4680 if isinstance (line , MultiLineString ):
4781 for g in line .geoms :
48- ax .plot (* g .xy , transform = ccrs .PlateCarree (), color = "blue" )
82+ ax .plot (
83+ * g .xy , transform = ccrs .PlateCarree (), color = c , label = t , linewidth = 0.7
84+ )
4985 else :
50- ax .plot (* line .xy , transform = ccrs .PlateCarree (), color = "blue" )
51-
86+ ax .plot (
87+ * line .xy , transform = ccrs .PlateCarree (), color = c , label = t , linewidth = 0.7
88+ )
89+
90+ # plot the legend
91+ handles , labels = ax .get_legend_handles_labels ()
92+ unique = [
93+ (h , l ) for i , (h , l ) in enumerate (zip (handles , labels )) if l not in labels [:i ]
94+ ]
95+ legend = plt .legend (
96+ * zip (* unique ),
97+ title = "Feature Types" ,
98+ prop = {"size" : 6 },
99+ loc = "lower right" ,
100+ bbox_to_anchor = (1.1 , 0.9 ),
101+ )
102+ plt .setp (legend .get_title (), fontsize = "xx-small" )
52103 plt .title (f"{ time } Ma" )
53104 if show :
54105 plt .show ()
0 commit comments