1616https://simpsons.fandom.com/wiki/Brockway.
1717
1818"""
19+
1920import matplotlib .pyplot as plt
2021from matplotlib .transforms import offset_copy
2122
@@ -39,11 +40,14 @@ def main():
3940 # Set up a plot with a thin light blue/white border to make the map inside
4041 # Note: for proportions of land mass, font size and border to be as
4142 # intended, need to keep 'figsize' and 'dpi' (4:3 ratio) as below.
42- fig , ax = plt .subplots (figsize = (9 , 7.5 ), dpi = 125 , facecolor = "white" )
43- ax .set_facecolor ("#AFCBBD" )
44- ax = fig .add_subplot (111 , projection = ccrs .LambertConformal (), frameon = False )
45- plt .setp (plt .gcf ().get_axes (), xticks = [], yticks = []) # no axes or labels
46- ax .set_extent ([- 120 , - 72.5 , 20 , 50 ], crs = ccrs .Geodetic ()) # center on USA
43+ fig = plt .figure (figsize = (9 , 7.5 ), dpi = 125 , facecolor = "#AFCBBD" )
44+ map_ax = fig .add_axes (
45+ [0.035 , 0.035 , 0.93 , 0.93 ], projection = ccrs .LambertConformal (), frameon = False
46+ )
47+
48+ # Remove all axes ticks and labelling and center on location of USA
49+ plt .setp (map_ax , xticks = [], yticks = [])
50+ map_ax .set_extent ([- 120 , - 72.5 , 20 , 50 ], crs = ccrs .Geodetic ())
4751
4852 # Plot only the USA landmass, in a fawn colour with a thin black border
4953 shpfilename = shpreader .natural_earth (
@@ -55,7 +59,7 @@ def main():
5559 for country in countries
5660 if (country .attributes ["NAME" ] == "United States of America" )
5761 ]
58- ax .add_geometries (
62+ map_ax .add_geometries (
5963 usa_border ,
6064 GEOM_PROJ ,
6165 facecolor = "#C39B6A" ,
@@ -71,11 +75,11 @@ def main():
7175 # for the Geodetic coordinate system. We will use this along with
7276 # matplotlib's offset_copy function to define a coordinate system which
7377 # translates the text by 25 pixels to the left.
74- geodetic_transform = GEOM_PROJ ._as_mpl_transform (ax )
78+ geodetic_transform = GEOM_PROJ ._as_mpl_transform (map_ax )
7579 text_transform = offset_copy (geodetic_transform , units = "dots" , x = - 25 )
7680 for loc_name , loc_details in LOCATIONS_TO_PLOT .items ():
7781 loc_coords , rel_text_pos , text_rot = loc_details
78- ax .plot (
82+ map_ax .plot (
7983 * loc_coords ,
8084 marker = "o" ,
8185 color = "black" ,
@@ -90,7 +94,7 @@ def main():
9094 )
9195 # Text in uppercase, very bold handwriting-like font, as per the
9296 # screen grab of the map from the show
93- ax .text (
97+ map_ax .text (
9498 * text_loc_coords ,
9599 loc_name .upper (),
96100 verticalalignment = "center" ,
@@ -108,21 +112,18 @@ def main():
108112 )
109113
110114 # Add the 'compass' legend
111- ax .text (
115+ map_ax .text (
112116 0.14 ,
113117 0.10 ,
114118 leg_text ,
115- transform = ax .transAxes ,
119+ transform = map_ax .transAxes ,
116120 fontsize = 11 ,
117121 horizontalalignment = "center" ,
118122 verticalalignment = "center" ,
119123 style = "italic" ,
120124 bbox = dict (facecolor = "#A5B5CE" ),
121125 )
122126
123- # Make border symmetrical since default 'rc' file has asymmetric side pad
124- fig .tight_layout ()
125- fig .subplots_adjust (left = 0.035 , bottom = 0.035 , right = 0.965 , top = 0.965 )
126127 plt .show ()
127128
128129
0 commit comments