Skip to content

Conversation

@TTV-Intrepid
Copy link

🚀 Pull Request

Description

This example demonstrates aligning a linear plot and a cartographic plot using Matplotlib.


Consult Iris pull request check list

Copy link
Contributor

@trexfeathers trexfeathers left a comment

Choose a reason for hiding this comment

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

Super job @TTV-Intrepid, thanks for the PR!

This already works perfectly; I've just got some suggestions to make it as clear as possible for the reader.

Comment on lines +50 to +54
# Round each tick for the third ax to the nearest 20 (ready for use).
data_max = collapsed_temp.data.max()
x_max = data_max - data_max % -20
data_min = collapsed_temp.data.min()
x_min = data_min - data_min % 20
Copy link
Contributor

Choose a reason for hiding this comment

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

You could move this block after the ax3 block so that it can include the ax3.set_xlim(x_min, x_max) line, too.

Comment on lines +24 to +27
# Set y axes with -90 and 90 limits and spacing of 15 per tick.
yticks = np.arange(-90, 105, 15)
ylim = [-90, 90]
fig = plt.figure(figsize=[12, 4])
Copy link
Contributor

Choose a reason for hiding this comment

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

This deserves its own code block, as it's not directly related to the following code.

Suggested change
# Set y axes with -90 and 90 limits and spacing of 15 per tick.
yticks = np.arange(-90, 105, 15)
ylim = [-90, 90]
fig = plt.figure(figsize=[12, 4])
# Set y axes with -90 and 90 limits and spacing of 15 per tick.
yticks = np.arange(-90, 105, 15)
ylim = [-90, 90]
# Plot "temperature" on a cartographic plot and set the ticks and titles on the axes.
fig = plt.figure(figsize=[12, 4])

ax1.set_ylabel("latitude")
ax1.set_xlabel("longitude")
ax1.set_ylim(*ylim)
divider = make_axes_locatable(ax1)
Copy link
Contributor

Choose a reason for hiding this comment

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

This is the 'magic sauce' that makes it possible to align everything, so it should have some extra emphasis. I've done a bit of reading to work out an appropriate comment:

Suggested change
divider = make_axes_locatable(ax1)
# Create a Matplotlib AxesDivider object to allow alignment of other Axes objects.
divider = make_axes_locatable(ax1)

fig.add_axes(ax2)
plt.sca(ax2)
cbar = plt.colorbar(im, cax=ax2, orientation="horizontal")
cbar.ax.set_xlabel("Air Temperature [k]")
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
cbar.ax.set_xlabel("Air Temperature [k]")
cbar.ax.set_xlabel("Air Temperature [K]")

Reference

ax3.set_ylim(*ylim)
ax3.set_title("Zonal mean")
ax3.set_ylabel("latitude")
ax3.set_xlabel("Air Temperature [k]")
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
ax3.set_xlabel("Air Temperature [k]")
ax3.set_xlabel("Air Temperature [K]")

Reference

plt.sca(ax3)
iplt.plot(collapsed_temp, collapsed_temp.coord("latitude"))
ax3.axvline(0, color="k", linewidth=0.5)
ax3.set_ylim(*ylim)
Copy link
Contributor

Choose a reason for hiding this comment

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

Swap position with ax3.set_yticks(yticks) - for consistency with the ax1 block.

@rcomer rcomer mentioned this pull request Jul 20, 2022
@trexfeathers
Copy link
Contributor

Closing as @TTV-Intrepid is no longer available to complete this work.

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.

2 participants