-
Notifications
You must be signed in to change notification settings - Fork 298
Zonal mean gallery example #4871
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
Conversation
for more information, see https://pre-commit.ci
trexfeathers
left a comment
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.
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.
| # 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 |
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.
You could move this block after the ax3 block so that it can include the ax3.set_xlim(x_min, x_max) line, too.
| # 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]) |
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.
This deserves its own code block, as it's not directly related to the following code.
| # 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) |
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.
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:
| 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]") |
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.
| cbar.ax.set_xlabel("Air Temperature [k]") | |
| cbar.ax.set_xlabel("Air Temperature [K]") |
| ax3.set_ylim(*ylim) | ||
| ax3.set_title("Zonal mean") | ||
| ax3.set_ylabel("latitude") | ||
| ax3.set_xlabel("Air Temperature [k]") |
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.
| ax3.set_xlabel("Air Temperature [k]") | |
| ax3.set_xlabel("Air Temperature [K]") |
| plt.sca(ax3) | ||
| iplt.plot(collapsed_temp, collapsed_temp.coord("latitude")) | ||
| ax3.axvline(0, color="k", linewidth=0.5) | ||
| ax3.set_ylim(*ylim) |
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.
Swap position with ax3.set_yticks(yticks) - for consistency with the ax1 block.
|
Closing as @TTV-Intrepid is no longer available to complete this work. |
🚀 Pull Request
Description
This example demonstrates aligning a linear plot and a cartographic plot using Matplotlib.
Consult Iris pull request check list