Skip to content

Conversation

@sadielbartholomew
Copy link
Contributor

@sadielbartholomew sadielbartholomew commented Oct 23, 2025

Rationale

For fun (and love of said TV Series), I have recreated the Monorail Map from The Simpsons using Cartopy - the challenge was to get as close to likeness as I could using the standard Python visualisation ecosystem - matplotlib etc, in a small-ish script, and Cartopy made this simple.

Whist I did this mostly with the motivation of making high-res print outs for myself, I think it would make a good example for your examples gallery. As I summarise in the top-level docstring:

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,

Moreover, other vis libraries with examples galleries have humorous examples - notably the XKCD examples - so I think i is nice to add (another) one to the Cartopy examples gallery.

From other PRs adding new examples I have found from a quick search, it seems that I just need to add the new script in the appropriate place under 'cartopy/examples/` and the relevant subdirectory to categorise - I think 'miscellanea' is most suitable, but happy to move it if you wish.

Please let me know if you would like me to adjust it in any way if you would accept it for the gallery - either codewise or output-wise.

Implications

A new example recipe will be added to the docs and maybe somebody will find it useful and/or amusing. 🙂

Notes

The output (with Python 3.12) is this:

monorail_map

For reference, the original looks like this.

@CLAassistant
Copy link

CLAassistant commented Oct 23, 2025

CLA assistant check
All committers have signed the CLA.

@sadielbartholomew sadielbartholomew changed the title DOC: new misc. example, recreation of The Simpsons Monorail Map DOC: new example, recreation of The Simpsons Monorail Map Oct 23, 2025
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can call set directly on the axes you already have here.

Suggested change
plt.setp(plt.gcf().get_axes(), xticks=[], yticks=[]) # no axes or labels
ax.set(xticks=[], yticks=[]) # no axes or labels

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried this suggestion instead but (using the cartopy-dev environment as per the contributors guide) then I do see the axes labels:

Figure_1monorailmap

So if there is an axes object based approach, something else seems to be required?

Comment on lines +42 to +44
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you create the figure and then the single axes? I'm not sure why you need to two "ax" here.

Suggested change
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)
fig = plt.figure(figsize=(9, 7.5))
ax = fig.add_subplot(111, projection=ccrs.LambertConformal(), frameon=False)
ax.set_facecolor("#AFCBBD")

Copy link
Contributor Author

@sadielbartholomew sadielbartholomew Oct 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your suggestion above doesn't quite work and gives me this:

Figure_1monorail_map2

but good point about the double use of ax - I will work out a way to avoid that and report back. Thanks.

)

# Make border symmetrical since default 'rc' file has asymmetric side pad
fig.tight_layout()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you are trying to place things just right, we probably shouldn't call tight_layout at all since that adjusts all of the pads/trims things down.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough, thanks for pointing this out. I will remove it in a feedback-response commit which I will push shortly.


# 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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want to call add_axes() above to make an explicit placement in figure space?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will try playing around with use of add_axes, though from your previous comment it seems we don't want multiple axes so I am a bit confused as to how that fits with said plan - unless I use that to create the one and only axis. Would be useful if you can clarify?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the confusion, I was making various comments depending on which direction you were going to go. I agree with only one axes, how you put it in depends on what you want to do with it. If you want to explicitly place it or for it to take up the entire figure then I would manually place it with ax = fig.add_axes([0, 0, 1, 1], projection=GEOM_PROJ) (or subtract the margins you have above as necessary)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants