From 90b834c65246ebb46b587ae28b3314e761c10a8a Mon Sep 17 00:00:00 2001 From: "Sadie L. Bartholomew" Date: Thu, 23 Oct 2025 19:37:52 +0100 Subject: [PATCH 01/14] Add script for new example recreating monorail map in The Simpsons --- examples/miscellanea/simpsons-monorail-map.py | 114 ++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 examples/miscellanea/simpsons-monorail-map.py diff --git a/examples/miscellanea/simpsons-monorail-map.py b/examples/miscellanea/simpsons-monorail-map.py new file mode 100644 index 000000000..b6b6fc87a --- /dev/null +++ b/examples/miscellanea/simpsons-monorail-map.py @@ -0,0 +1,114 @@ +import matplotlib.patches as mpatches +import matplotlib.pyplot as plt +from matplotlib.transforms import offset_copy + +import shapely.geometry as sgeom + +import cartopy +import cartopy.crs as ccrs +import cartopy.io.shapereader as shpreader +import cartopy.feature as cfeature + + +# Define choices for projection and locations to plot +GEOM_PROJ = ccrs.PlateCarree() +# Not real places, so locations pulled from location on map in still image +# First value 2-tuple is the dot placemap location, second is where to write +# the text label relative to that dot, to best match the map from the show. +LOCATIONS_TO_PLOT = { + "Ogdenville": [(-111.8, 35.5), (1.5, -2.2), -6], + "North\nHaverbrook": [(-99.0, 43.5), (2.8, -0.5), -1], + "Brockway": [(-80.4, 33.6), (-3.4, -1.5), 3], +} + + +def main(): + # Set up a plot with a thin light blue/white border to make the map inside + # Note: for proportions of land mass, font size and border to be as + # intended, need to keep 'figsize' and 'dpi' (4:3 ratio) as below. + fig, ax = plt.subplots(figsize=(9, 7.5), dpi=125, facecolor="white") + ax.set_facecolor("#AFCBBD") + ax = fig.add_subplot( + 111, projection=ccrs.LambertConformal(), frameon=False) + plt.setp(plt.gcf().get_axes(), xticks=[], yticks=[]) # no axes or labels + ax.set_extent([-120, -72.5, 20, 50], crs=ccrs.Geodetic()) # center on USA + + # Plot only the USA landmass, in a fawn colour with a thin black border + shpfilename = shpreader.natural_earth( + resolution="110m", category="cultural", name="admin_0_countries" + ) + countries = shpreader.Reader(shpfilename).records() + usa_border = [ + country.geometry for country in countries + if (country.attributes["NAME"] == "United States of America") + ] + ax.add_geometries( + usa_border, + GEOM_PROJ, + facecolor="#C39B6A", + edgecolor="black", + ) + + # From/see example: + # https://scitools.org.uk/cartopy/docs/latest/gallery/ + # scalar_data/eyja_volcano.html + # Now add the location labels + # + # Use the cartopy interface to create a matplotlib transform object + # for the Geodetic coordinate system. We will use this along with + # matplotlib's offset_copy function to define a coordinate system which + # translates the text by 25 pixels to the left. + geodetic_transform = GEOM_PROJ._as_mpl_transform(ax) + text_transform = offset_copy(geodetic_transform, units="dots", x=-25) + for loc_name, loc_details in LOCATIONS_TO_PLOT.items(): + loc_coords, rel_text_pos, text_rot = loc_details + ax.plot( + *loc_coords, + marker="o", + color="black", + markersize=6, + transform=GEOM_PROJ, + ) + + # Adjust position of location name text relative to location marker + text_loc_coords = ( + loc_coords[0] + rel_text_pos[0], + loc_coords[1] + rel_text_pos[1], + ) + # Text in uppercase, very bold handwriting-like font, as per the + # screengrab + ax.text( + *text_loc_coords, + loc_name.upper(), + verticalalignment="center", + horizontalalignment="left", + transform=text_transform, + fontname="Charcoal", # ensure you have this font available + fontweight="black", + fontsize=28, + rotation=text_rot, # slightly wonky text for handwritten effect + ) + + + leg_text = ( + "Pre-Springfield Lanley\nMonorail locations in TV's\nThe Simpsons\n" + "(recreation of map at\nsimpsons.fandom.com/\nwiki/Brockway)" + ) + + # Add the 'compass' legend + ax.text( + 0.14, 0.10, leg_text, transform=ax.transAxes, fontsize=11, + horizontalalignment="center", + verticalalignment="center", style="italic", + bbox=dict(facecolor="#A5B5CE"), + ) + + # Make border symmetrical since default 'rc' file has asymmetric side pad + fig.tight_layout() + fig.subplots_adjust(left=0.035, bottom=0.035, right=0.965, top=0.965) + plt.show() + fig.savefig("monorail_map.png") + + +if __name__ == "__main__": + main() From 0dd1e49302e08fd068805899c8a4c5fcb1e7ce03 Mon Sep 17 00:00:00 2001 From: "Sadie L. Bartholomew" Date: Thu, 23 Oct 2025 19:39:37 +0100 Subject: [PATCH 02/14] Lint Monorail Map example w/ black & remove unused imports --- examples/miscellanea/simpsons-monorail-map.py | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/examples/miscellanea/simpsons-monorail-map.py b/examples/miscellanea/simpsons-monorail-map.py index b6b6fc87a..0589b09c8 100644 --- a/examples/miscellanea/simpsons-monorail-map.py +++ b/examples/miscellanea/simpsons-monorail-map.py @@ -1,13 +1,8 @@ -import matplotlib.patches as mpatches import matplotlib.pyplot as plt from matplotlib.transforms import offset_copy -import shapely.geometry as sgeom - -import cartopy import cartopy.crs as ccrs import cartopy.io.shapereader as shpreader -import cartopy.feature as cfeature # Define choices for projection and locations to plot @@ -28,8 +23,7 @@ def main(): # intended, need to keep 'figsize' and 'dpi' (4:3 ratio) as below. fig, ax = plt.subplots(figsize=(9, 7.5), dpi=125, facecolor="white") ax.set_facecolor("#AFCBBD") - ax = fig.add_subplot( - 111, projection=ccrs.LambertConformal(), frameon=False) + ax = fig.add_subplot(111, projection=ccrs.LambertConformal(), frameon=False) plt.setp(plt.gcf().get_axes(), xticks=[], yticks=[]) # no axes or labels ax.set_extent([-120, -72.5, 20, 50], crs=ccrs.Geodetic()) # center on USA @@ -39,7 +33,8 @@ def main(): ) countries = shpreader.Reader(shpfilename).records() usa_border = [ - country.geometry for country in countries + country.geometry + for country in countries if (country.attributes["NAME"] == "United States of America") ] ax.add_geometries( @@ -89,7 +84,6 @@ def main(): rotation=text_rot, # slightly wonky text for handwritten effect ) - leg_text = ( "Pre-Springfield Lanley\nMonorail locations in TV's\nThe Simpsons\n" "(recreation of map at\nsimpsons.fandom.com/\nwiki/Brockway)" @@ -97,9 +91,14 @@ def main(): # Add the 'compass' legend ax.text( - 0.14, 0.10, leg_text, transform=ax.transAxes, fontsize=11, + 0.14, + 0.10, + leg_text, + transform=ax.transAxes, + fontsize=11, horizontalalignment="center", - verticalalignment="center", style="italic", + verticalalignment="center", + style="italic", bbox=dict(facecolor="#A5B5CE"), ) From 4e0822467160046ea866179068ccc377de6810aa Mon Sep 17 00:00:00 2001 From: "Sadie L. Bartholomew" Date: Thu, 23 Oct 2025 20:14:21 +0100 Subject: [PATCH 03/14] Add module docstring to summarise Monorail Map example --- examples/miscellanea/simpsons-monorail-map.py | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/examples/miscellanea/simpsons-monorail-map.py b/examples/miscellanea/simpsons-monorail-map.py index 0589b09c8..03fd4b657 100644 --- a/examples/miscellanea/simpsons-monorail-map.py +++ b/examples/miscellanea/simpsons-monorail-map.py @@ -1,3 +1,21 @@ +""" +Recreation of the Monorail Map from The Simpsons +------------------------------------------------ + +This example demonstrates how to create a minimal outline map of a +defined area of land such as a continent, with optional labels at +specified locations within the region, in the form of a recreation of the +Monorail Map from The Simpsons with humorously oversized labelling (to +imitate handwriting/scribbles) and sparsity of marked locations +(which are all fictional). + +Specifically, it aims to recreate to best likeness using Cartopy +the map of pre-Springfield Lyle Lanley Monorail locations from the +iconic episode 'Marge vs. the Monorail' (1993) of the TV Series, as +taken in likeness from the screen grab available at: +https://simpsons.fandom.com/wiki/Brockway. + +""" import matplotlib.pyplot as plt from matplotlib.transforms import offset_copy @@ -71,7 +89,7 @@ def main(): loc_coords[1] + rel_text_pos[1], ) # Text in uppercase, very bold handwriting-like font, as per the - # screengrab + # screen grab of the map from the show ax.text( *text_loc_coords, loc_name.upper(), From be4f92755c124ad9f3f3b211930e9ddb5f9b62ea Mon Sep 17 00:00:00 2001 From: "Sadie L. Bartholomew" Date: Thu, 30 Oct 2025 18:10:25 +0000 Subject: [PATCH 04/14] Update examples/miscellanea/simpsons-monorail-map.py Co-authored-by: Greg Lucas --- examples/miscellanea/simpsons-monorail-map.py | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/miscellanea/simpsons-monorail-map.py b/examples/miscellanea/simpsons-monorail-map.py index 03fd4b657..823a61967 100644 --- a/examples/miscellanea/simpsons-monorail-map.py +++ b/examples/miscellanea/simpsons-monorail-map.py @@ -124,7 +124,6 @@ def main(): fig.tight_layout() fig.subplots_adjust(left=0.035, bottom=0.035, right=0.965, top=0.965) plt.show() - fig.savefig("monorail_map.png") if __name__ == "__main__": From 05f29a598e2444d3a7029b3f0d2ba0932c0e5b72 Mon Sep 17 00:00:00 2001 From: "Sadie L. Bartholomew" Date: Mon, 3 Nov 2025 12:14:57 +0000 Subject: [PATCH 05/14] Address feedback: better figure, axes use in Monorail Map example --- examples/miscellanea/simpsons-monorail-map.py | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/examples/miscellanea/simpsons-monorail-map.py b/examples/miscellanea/simpsons-monorail-map.py index 823a61967..043b19e31 100644 --- a/examples/miscellanea/simpsons-monorail-map.py +++ b/examples/miscellanea/simpsons-monorail-map.py @@ -16,6 +16,7 @@ https://simpsons.fandom.com/wiki/Brockway. """ + import matplotlib.pyplot as plt from matplotlib.transforms import offset_copy @@ -39,11 +40,14 @@ def main(): # Set up a plot with a thin light blue/white border to make the map inside # Note: for proportions of land mass, font size and border to be as # intended, need to keep 'figsize' and 'dpi' (4:3 ratio) as below. - fig, ax = plt.subplots(figsize=(9, 7.5), dpi=125, facecolor="white") - ax.set_facecolor("#AFCBBD") - ax = fig.add_subplot(111, projection=ccrs.LambertConformal(), frameon=False) - plt.setp(plt.gcf().get_axes(), xticks=[], yticks=[]) # no axes or labels - ax.set_extent([-120, -72.5, 20, 50], crs=ccrs.Geodetic()) # center on USA + fig = plt.figure(figsize=(9, 7.5), dpi=125, facecolor="#AFCBBD") + map_ax = fig.add_axes( + [0.035, 0.035, 0.93, 0.93], projection=ccrs.LambertConformal(), frameon=False + ) + + # Remove all axes ticks and labelling and center on location of USA + plt.setp(map_ax, xticks=[], yticks=[]) + map_ax.set_extent([-120, -72.5, 20, 50], crs=ccrs.Geodetic()) # Plot only the USA landmass, in a fawn colour with a thin black border shpfilename = shpreader.natural_earth( @@ -55,7 +59,7 @@ def main(): for country in countries if (country.attributes["NAME"] == "United States of America") ] - ax.add_geometries( + map_ax.add_geometries( usa_border, GEOM_PROJ, facecolor="#C39B6A", @@ -71,11 +75,11 @@ def main(): # for the Geodetic coordinate system. We will use this along with # matplotlib's offset_copy function to define a coordinate system which # translates the text by 25 pixels to the left. - geodetic_transform = GEOM_PROJ._as_mpl_transform(ax) + geodetic_transform = GEOM_PROJ._as_mpl_transform(map_ax) text_transform = offset_copy(geodetic_transform, units="dots", x=-25) for loc_name, loc_details in LOCATIONS_TO_PLOT.items(): loc_coords, rel_text_pos, text_rot = loc_details - ax.plot( + map_ax.plot( *loc_coords, marker="o", color="black", @@ -90,7 +94,7 @@ def main(): ) # Text in uppercase, very bold handwriting-like font, as per the # screen grab of the map from the show - ax.text( + map_ax.text( *text_loc_coords, loc_name.upper(), verticalalignment="center", @@ -108,11 +112,11 @@ def main(): ) # Add the 'compass' legend - ax.text( + map_ax.text( 0.14, 0.10, leg_text, - transform=ax.transAxes, + transform=map_ax.transAxes, fontsize=11, horizontalalignment="center", verticalalignment="center", @@ -120,9 +124,6 @@ def main(): bbox=dict(facecolor="#A5B5CE"), ) - # Make border symmetrical since default 'rc' file has asymmetric side pad - fig.tight_layout() - fig.subplots_adjust(left=0.035, bottom=0.035, right=0.965, top=0.965) plt.show() From 5ba69508ac1f59bb56e8ae191d870deaab75bb5b Mon Sep 17 00:00:00 2001 From: "Sadie L. Bartholomew" Date: Mon, 3 Nov 2025 12:43:28 +0000 Subject: [PATCH 06/14] Monorail map example: add border using figure edge + tidy comments --- examples/miscellanea/simpsons-monorail-map.py | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/examples/miscellanea/simpsons-monorail-map.py b/examples/miscellanea/simpsons-monorail-map.py index 043b19e31..0283aca5d 100644 --- a/examples/miscellanea/simpsons-monorail-map.py +++ b/examples/miscellanea/simpsons-monorail-map.py @@ -22,6 +22,7 @@ import cartopy.crs as ccrs import cartopy.io.shapereader as shpreader +from matplotlib.patches import Rectangle # Define choices for projection and locations to plot @@ -37,10 +38,16 @@ def main(): - # Set up a plot with a thin light blue/white border to make the map inside - # Note: for proportions of land mass, font size and border to be as - # intended, need to keep 'figsize' and 'dpi' (4:3 ratio) as below. - fig = plt.figure(figsize=(9, 7.5), dpi=125, facecolor="#AFCBBD") + # Set up a plot with a light blue background and a white overall border. + # For proportions of land mass, font size and border to be as + # intended, need to keep 'figsize' and 'dpi' (4:3 ratio) as below. + fig = plt.figure( + figsize=(9, 7.5), + dpi=125, + facecolor="#AFCBBD", + edgecolor="white", # sets up white border without need for another axes + linewidth=30, # makes the border thicker as per original map + ) map_ax = fig.add_axes( [0.035, 0.035, 0.93, 0.93], projection=ccrs.LambertConformal(), frameon=False ) @@ -66,10 +73,8 @@ def main(): edgecolor="black", ) - # From/see example: - # https://scitools.org.uk/cartopy/docs/latest/gallery/ - # scalar_data/eyja_volcano.html - # Now add the location labels + # Now add the location labels. The general approach is that covered in + # the 'Map tile acquisition' Catopy example, including the comment below. # # Use the cartopy interface to create a matplotlib transform object # for the Geodetic coordinate system. We will use this along with @@ -111,10 +116,10 @@ def main(): "(recreation of map at\nsimpsons.fandom.com/\nwiki/Brockway)" ) - # Add the 'compass' legend + # Add the bottom left 'compass' legend in spirit of the original map. map_ax.text( 0.14, - 0.10, + 0.0, leg_text, transform=map_ax.transAxes, fontsize=11, From dfd5542fb1a66f59ff18e2f1e51c901bf3f3b23d Mon Sep 17 00:00:00 2001 From: "Sadie L. Bartholomew" Date: Mon, 3 Nov 2025 12:57:08 +0000 Subject: [PATCH 07/14] Monorail map example: use ax not setp object to hide axes & labels Co-authored-by: Greg Lucas --- examples/miscellanea/simpsons-monorail-map.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/miscellanea/simpsons-monorail-map.py b/examples/miscellanea/simpsons-monorail-map.py index 0283aca5d..094c27034 100644 --- a/examples/miscellanea/simpsons-monorail-map.py +++ b/examples/miscellanea/simpsons-monorail-map.py @@ -53,7 +53,7 @@ def main(): ) # Remove all axes ticks and labelling and center on location of USA - plt.setp(map_ax, xticks=[], yticks=[]) + map_ax.set(xticks=[], yticks=[]) map_ax.set_extent([-120, -72.5, 20, 50], crs=ccrs.Geodetic()) # Plot only the USA landmass, in a fawn colour with a thin black border From 701ca1572c7f20f1305fda06d2658ce4ceed7515 Mon Sep 17 00:00:00 2001 From: "Sadie L. Bartholomew" Date: Tue, 4 Nov 2025 15:08:13 +0000 Subject: [PATCH 08/14] Monorail map example: remove redundant call to turn off axes ticks --- examples/miscellanea/simpsons-monorail-map.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/examples/miscellanea/simpsons-monorail-map.py b/examples/miscellanea/simpsons-monorail-map.py index 094c27034..4a64e81dd 100644 --- a/examples/miscellanea/simpsons-monorail-map.py +++ b/examples/miscellanea/simpsons-monorail-map.py @@ -52,8 +52,7 @@ def main(): [0.035, 0.035, 0.93, 0.93], projection=ccrs.LambertConformal(), frameon=False ) - # Remove all axes ticks and labelling and center on location of USA - map_ax.set(xticks=[], yticks=[]) + # Center on location of USA with a bit of space on all sides to pad map_ax.set_extent([-120, -72.5, 20, 50], crs=ccrs.Geodetic()) # Plot only the USA landmass, in a fawn colour with a thin black border From 1468b5ca0f4cf968d02c360b0d146f294146fbba Mon Sep 17 00:00:00 2001 From: "Sadie L. Bartholomew" Date: Tue, 18 Nov 2025 13:33:03 +0000 Subject: [PATCH 09/14] Use annotate to avoid internal method in new example, following #2596 --- examples/miscellanea/simpsons-monorail-map.py | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/examples/miscellanea/simpsons-monorail-map.py b/examples/miscellanea/simpsons-monorail-map.py index 4a64e81dd..5263f9982 100644 --- a/examples/miscellanea/simpsons-monorail-map.py +++ b/examples/miscellanea/simpsons-monorail-map.py @@ -72,15 +72,7 @@ def main(): edgecolor="black", ) - # Now add the location labels. The general approach is that covered in - # the 'Map tile acquisition' Catopy example, including the comment below. - # - # Use the cartopy interface to create a matplotlib transform object - # for the Geodetic coordinate system. We will use this along with - # matplotlib's offset_copy function to define a coordinate system which - # translates the text by 25 pixels to the left. - geodetic_transform = GEOM_PROJ._as_mpl_transform(map_ax) - text_transform = offset_copy(geodetic_transform, units="dots", x=-25) + # Now add the location labels one by one for loc_name, loc_details in LOCATIONS_TO_PLOT.items(): loc_coords, rel_text_pos, text_rot = loc_details map_ax.plot( @@ -98,12 +90,14 @@ def main(): ) # Text in uppercase, very bold handwriting-like font, as per the # screen grab of the map from the show - map_ax.text( - *text_loc_coords, + map_ax.annotate( loc_name.upper(), + xy=text_loc_coords, + transform=ccrs.Geodetic(), + xytext=(-25, 0), # shift text closer to point as per reference + textcoords="offset pixels", verticalalignment="center", horizontalalignment="left", - transform=text_transform, fontname="Charcoal", # ensure you have this font available fontweight="black", fontsize=28, From 0f018e624c5df9d49f58e1c6fe170fbfbb8b7405 Mon Sep 17 00:00:00 2001 From: "Sadie L. Bartholomew" Date: Tue, 18 Nov 2025 13:39:29 +0000 Subject: [PATCH 10/14] Monorail map example: adjust legend-like box given altered dimensions --- examples/miscellanea/simpsons-monorail-map.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/miscellanea/simpsons-monorail-map.py b/examples/miscellanea/simpsons-monorail-map.py index 5263f9982..246ba15e2 100644 --- a/examples/miscellanea/simpsons-monorail-map.py +++ b/examples/miscellanea/simpsons-monorail-map.py @@ -112,7 +112,7 @@ def main(): # Add the bottom left 'compass' legend in spirit of the original map. map_ax.text( 0.14, - 0.0, + 0.10, leg_text, transform=map_ax.transAxes, fontsize=11, From 0479aac5385f5ef5ac7783120a6d3c94d048b28c Mon Sep 17 00:00:00 2001 From: "Sadie L. Bartholomew" Date: Fri, 21 Nov 2025 11:47:52 +0000 Subject: [PATCH 11/14] Monorail map example: remove now unused imports --- examples/miscellanea/simpsons-monorail-map.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/examples/miscellanea/simpsons-monorail-map.py b/examples/miscellanea/simpsons-monorail-map.py index 246ba15e2..e98f5857f 100644 --- a/examples/miscellanea/simpsons-monorail-map.py +++ b/examples/miscellanea/simpsons-monorail-map.py @@ -18,11 +18,9 @@ """ import matplotlib.pyplot as plt -from matplotlib.transforms import offset_copy import cartopy.crs as ccrs import cartopy.io.shapereader as shpreader -from matplotlib.patches import Rectangle # Define choices for projection and locations to plot From 6dac22686d1ecaee830599e75d9a88af02d1da4c Mon Sep 17 00:00:00 2001 From: "Sadie L. Bartholomew" Date: Fri, 21 Nov 2025 11:57:13 +0000 Subject: [PATCH 12/14] Monorail map example: improve comment describing locations dictionary --- examples/miscellanea/simpsons-monorail-map.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/examples/miscellanea/simpsons-monorail-map.py b/examples/miscellanea/simpsons-monorail-map.py index e98f5857f..a57d48ad0 100644 --- a/examples/miscellanea/simpsons-monorail-map.py +++ b/examples/miscellanea/simpsons-monorail-map.py @@ -25,9 +25,11 @@ # Define choices for projection and locations to plot GEOM_PROJ = ccrs.PlateCarree() -# Not real places, so locations pulled from location on map in still image -# First value 2-tuple is the dot placemap location, second is where to write -# the text label relative to that dot, to best match the map from the show. +# Not real places, so locations pulled from location on map in still image. +# The items in order correspond to: +# * an x-y 2-tuple for where to plot the location dot on the map +# * an x-y 2-tuple for where to write the text label relative to the dot above +# * an integer for how much to rotate the text to best match the map text. LOCATIONS_TO_PLOT = { "Ogdenville": [(-111.8, 35.5), (1.5, -2.2), -6], "North\nHaverbrook": [(-99.0, 43.5), (2.8, -0.5), -1], From 51631edc3ad19b386db2a27bb5bc57e3044ffd6d Mon Sep 17 00:00:00 2001 From: "Sadie L. Bartholomew" Date: Thu, 4 Dec 2025 09:37:46 +0000 Subject: [PATCH 13/14] Monorail map example: use points not degrees as per code feedback --- examples/miscellanea/simpsons-monorail-map.py | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/examples/miscellanea/simpsons-monorail-map.py b/examples/miscellanea/simpsons-monorail-map.py index a57d48ad0..b58223057 100644 --- a/examples/miscellanea/simpsons-monorail-map.py +++ b/examples/miscellanea/simpsons-monorail-map.py @@ -27,13 +27,14 @@ GEOM_PROJ = ccrs.PlateCarree() # Not real places, so locations pulled from location on map in still image. # The items in order correspond to: -# * an x-y 2-tuple for where to plot the location dot on the map +# * an x-y 2-tuple for where to plot the location dot on the map; # * an x-y 2-tuple for where to write the text label relative to the dot above +# with units of points; # * an integer for how much to rotate the text to best match the map text. LOCATIONS_TO_PLOT = { - "Ogdenville": [(-111.8, 35.5), (1.5, -2.2), -6], - "North\nHaverbrook": [(-99.0, 43.5), (2.8, -0.5), -1], - "Brockway": [(-80.4, 33.6), (-3.4, -1.5), 3], + "Ogdenville": [(-111.8, 35.5), (-10.0, -50.0), -6], + "North\nHaverbrook": [(-99.0, 43.5), (15.0, -15.0), -1], + "Brockway": [(-80.4, 33.6), (-100.0, -40.0), 3], } @@ -83,18 +84,13 @@ def main(): transform=GEOM_PROJ, ) - # Adjust position of location name text relative to location marker - text_loc_coords = ( - loc_coords[0] + rel_text_pos[0], - loc_coords[1] + rel_text_pos[1], - ) # Text in uppercase, very bold handwriting-like font, as per the # screen grab of the map from the show map_ax.annotate( loc_name.upper(), - xy=text_loc_coords, + xy=loc_coords, transform=ccrs.Geodetic(), - xytext=(-25, 0), # shift text closer to point as per reference + xytext=rel_text_pos, # shift text relative to marker as in map textcoords="offset pixels", verticalalignment="center", horizontalalignment="left", @@ -123,6 +119,7 @@ def main(): ) plt.show() + fig.savefig("monorail-dec-new.png") # SLB: REMOVE BEFORE COMMITTING if __name__ == "__main__": From b89e7af5189da93e8eab4c2bb6d7633917ee8201 Mon Sep 17 00:00:00 2001 From: "Sadie L. Bartholomew" Date: Thu, 4 Dec 2025 09:46:56 +0000 Subject: [PATCH 14/14] Monorail map example: adjust figure size & anchored legend position --- examples/miscellanea/simpsons-monorail-map.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/examples/miscellanea/simpsons-monorail-map.py b/examples/miscellanea/simpsons-monorail-map.py index b58223057..ea651f038 100644 --- a/examples/miscellanea/simpsons-monorail-map.py +++ b/examples/miscellanea/simpsons-monorail-map.py @@ -43,7 +43,7 @@ def main(): # For proportions of land mass, font size and border to be as # intended, need to keep 'figsize' and 'dpi' (4:3 ratio) as below. fig = plt.figure( - figsize=(9, 7.5), + figsize=(8., 6.5), dpi=125, facecolor="#AFCBBD", edgecolor="white", # sets up white border without need for another axes @@ -107,8 +107,8 @@ def main(): # Add the bottom left 'compass' legend in spirit of the original map. map_ax.text( - 0.14, - 0.10, + 0.15, + 0.02, leg_text, transform=map_ax.transAxes, fontsize=11, @@ -119,7 +119,6 @@ def main(): ) plt.show() - fig.savefig("monorail-dec-new.png") # SLB: REMOVE BEFORE COMMITTING if __name__ == "__main__":