-
Notifications
You must be signed in to change notification settings - Fork 389
DOC: new example, recreation of The Simpsons Monorail Map #2585
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sadielbartholomew
wants to merge
14
commits into
SciTools:main
Choose a base branch
from
sadielbartholomew:example-monorail-map-recreation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
90b834c
Add script for new example recreating monorail map in The Simpsons
sadielbartholomew 0dd1e49
Lint Monorail Map example w/ black & remove unused imports
sadielbartholomew 4e08224
Add module docstring to summarise Monorail Map example
sadielbartholomew be4f927
Update examples/miscellanea/simpsons-monorail-map.py
sadielbartholomew 05f29a5
Address feedback: better figure, axes use in Monorail Map example
sadielbartholomew 5ba6950
Monorail map example: add border using figure edge + tidy comments
sadielbartholomew dfd5542
Monorail map example: use ax not setp object to hide axes & labels
sadielbartholomew 701ca15
Monorail map example: remove redundant call to turn off axes ticks
sadielbartholomew 1468b5c
Use annotate to avoid internal method in new example, following #2596
sadielbartholomew 0f018e6
Monorail map example: adjust legend-like box given altered dimensions
sadielbartholomew 0479aac
Monorail map example: remove now unused imports
sadielbartholomew 6dac226
Monorail map example: improve comment describing locations dictionary
sadielbartholomew 51631ed
Monorail map example: use points not degrees as per code feedback
sadielbartholomew b89e7af
Monorail map example: adjust figure size & anchored legend position
sadielbartholomew File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| """ | ||
| 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 | ||
|
|
||
| import cartopy.crs as ccrs | ||
| import cartopy.io.shapereader as shpreader | ||
|
|
||
|
|
||
| # 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. | ||
| # 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 | ||
| # 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), (-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], | ||
| } | ||
|
|
||
|
|
||
| def main(): | ||
| # 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=(8., 6.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 | ||
| ) | ||
|
|
||
| # 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 | ||
| 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") | ||
| ] | ||
| map_ax.add_geometries( | ||
| usa_border, | ||
| GEOM_PROJ, | ||
| facecolor="#C39B6A", | ||
| edgecolor="black", | ||
| ) | ||
|
|
||
| # 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( | ||
| *loc_coords, | ||
| marker="o", | ||
| color="black", | ||
| markersize=6, | ||
| transform=GEOM_PROJ, | ||
| ) | ||
|
|
||
| # 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=loc_coords, | ||
| transform=ccrs.Geodetic(), | ||
| xytext=rel_text_pos, # shift text relative to marker as in map | ||
| textcoords="offset pixels", | ||
| verticalalignment="center", | ||
| horizontalalignment="left", | ||
| 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 bottom left 'compass' legend in spirit of the original map. | ||
| map_ax.text( | ||
| 0.15, | ||
| 0.02, | ||
| leg_text, | ||
| transform=map_ax.transAxes, | ||
| fontsize=11, | ||
| horizontalalignment="center", | ||
| verticalalignment="center", | ||
| style="italic", | ||
| bbox=dict(facecolor="#A5B5CE"), | ||
| ) | ||
|
|
||
| plt.show() | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional: could consider using AnchoredText here if you want the legend text right in the corner.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've left this just because I think I'd have to use
add_artistand a few related lines rather than the one-liner (spaced out to multiple lines as per PEP8/black code style) for the most direct way in the recipe/example but happy to still replace thetextcall withAnchoredText. If you and the Cartopy team prefer that then just let me know.