Skip to content
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

plt.subplots return is inconsistent #8571

Closed
KeithWM opened this issue May 4, 2017 · 4 comments
Closed

plt.subplots return is inconsistent #8571

KeithWM opened this issue May 4, 2017 · 4 comments

Comments

@KeithWM
Copy link

KeithWM commented May 4, 2017

This is not a bug, but a feature that I contend is implemented incorrectly.

When generating multiple subplots using fig, ax = plt.subplots(nrows, ncols) the returned 'axes' object(s) depend inconveniently on the number of rows and columns specified. Currently, the axes object is either a single object, a vector ax[i] or a matrix ax[i,j]. If the number of rows and/or columns is dynamically specified, this leads to convoluted programming to catch the different cases.

I believe it would be much more straightforward if it always returned an array of axes objects. If it can not be made the default, can it at least be added as a possibility via a keyword argument?

If this issue has been raised before, I apologise.

@jenshnielsen
Copy link
Member

jenshnielsen commented May 4, 2017

I think the squeeze kwarg should do exactly what you want? See http://matplotlib.org/api/pyplot_api.html?highlight=subplots#matplotlib.pyplot.subplots

@WeatherGod
Copy link
Member

There is:

    squeeze : bool, optional, default: True
        - If True, extra dimensions are squeezed out from the returned Axes
          object:
    
            - if only one subplot is constructed (nrows=ncols=1), the
              resulting single Axes object is returned as a scalar.
            - for Nx1 or 1xN subplots, the returned object is a 1D numpy
              object array of Axes objects are returned as numpy 1D arrays.
            - for NxM, subplots with N>1 and M>1 are returned as a 2D arrays.
    
        - If False, no squeezing at all is done: the returned Axes object is
          always a 2D array containing Axes instances, even if it ends up
          being 1x1.

@WeatherGod
Copy link
Member

Closing as the requested feature already exists.

@KeithWM
Copy link
Author

KeithWM commented May 4, 2017

Thanks for the quick response!

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

No branches or pull requests

3 participants