Skip to content

Replace subplot(ijk) calls by subplots(i, j) #18567

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

Merged
merged 1 commit into from
Sep 25, 2020

Conversation

timhoffm
Copy link
Member

PR Summary

Addresses part of the cases of #17335.

Plus some minor cleanup along the way.

@timhoffm timhoffm added this to the v3.4.0 milestone Sep 24, 2020
@@ -602,26 +602,21 @@ def test_fill_units():
dt = np.arange('2009-04-27', '2009-04-29', dtype='datetime64[D]')
dtn = mdates.date2num(dt)

fig = plt.figure()
fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2)
Copy link
Member

Choose a reason for hiding this comment

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

I am not a fan of this idiom versus fig, axs = plt.subplots(2, 2). You lose the ability to iterate if you spell them all out like this.

Copy link
Member

Choose a reason for hiding this comment

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

I think which is better depends on what you are doing (a grid of similar Axes or a grid of very different Axes).

In this case the code was previously using axN so this is the minimal touch to move away from add_subplot(XYZ).

Copy link
Member

Choose a reason for hiding this comment

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

And I think it also depends on the names you use,

fig, (ax_hist, ax_map) = plt.subplots(2)

seems much better that slicing into an array (which is similar to the argument of why subplot_mosaic returns a dict).

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree with @tacaswell, especially since this minimizes changes.

@@ -602,26 +602,21 @@ def test_fill_units():
dt = np.arange('2009-04-27', '2009-04-29', dtype='datetime64[D]')
dtn = mdates.date2num(dt)

fig = plt.figure()
fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2)
Copy link
Contributor

Choose a reason for hiding this comment

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

I agree with @tacaswell, especially since this minimizes changes.

@dopplershift dopplershift merged commit eeb32ac into matplotlib:master Sep 25, 2020
@timhoffm timhoffm deleted the subplot-cleanup branch September 25, 2020 07:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants