Skip to content

[ENH]: Syntax addition request to format subplots managed by pyplot.subplots #26944

Closed as not planned

Description

@yaredtds

Problem

  • Formating graphs managed by pyplot.subplots needs a lot of redundant typing or iterating on each subplots, and I think it can be done as follows.

*for example
import matplotlib.pyplot as plot
fig, ax = plt.subplots(2,2, figsize=(8,8))
ax[0,0].plot(x1,y1, label='x1,y1')
ax[0,1].plot(x2,y2, label='x2,y2')
ax[1,0].plot(x3,y3, label='x3,y3')
ax[1,1].plot(x4,y4, label='x4,y4')

  • Available syntax to add grid, label, legend, etc to each plots

  • method-1 looping
    [ax[i,j].grid(which='both') for i in range(2) for j in range(2)]

  • method-2 add grid, label, etc to each plots step by step in hardway
    ax[0,0].grid(which='both')
    ax[0,1].grid(which='both')
    ax[1,0].grid(which='both')
    ax[1,1].grid(which='both')

  • Feature Requested___
    ax[0:2,0].grid(which='both') # to set for first column
    ax[:,:].grid(which='both') # to set grid for all
    ax.grid(which='both') # to set grid for all

Proposed solution

I would like to propose these way of syntax to simplify formating multiple subplots

  • Feature Requested
    ax[0:2,0].grid(which='both') # to set for first column
    ax[:,:].grid(which='both') # to set grid for all
    ax.grid(which='both') # to set grid for all

thanks a lot and sorry if I do recommend this with limited understanding of your library. I request the above because I like it and want it to be better.

Have a nice day!

Activity

  1. rcomer commented on Sep 28, 2023

    @rcomer
    Member

    Currently the return value of subplots is a plain numpy array, so we can't do anything about the methods available on that. But there is a proposal to create our own AxesArray, which would make this sort of thing possible. See #25937.

  2. tacaswell commented on Sep 28, 2023

    @tacaswell
    Member

    Thank you for the suggestion @yaredtds .

    I am going to close is in favor of tracking the work in #25937 as the third selling point of that proposal is "add our own functionality".

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions