[Matplotlib-users] Axes array for subplots

Virgil Stokes vs at it.uu.se
Tue Apr 17 10:12:07 EDT 2018

The following line is part of a much larger python (3.6) with Matplotlib 
(2.2.2) program in which the number of subplots is determined from input 

fig, axarr = plt.subplots(NSub, figsize=(width,height), sharex=True)

This works fine when the number of subplots (NSub) is greater than 1. 
For example when NSub=3, axarr is an array of length 3 and contains:

array([<matplotlib.axes._subplots.AxesSubplot object at 
          <matplotlib.axes._subplots.AxesSubplot object at 
          <matplotlib.axes._subplots.AxesSubplot object at 

However, when NSub=1, axarr contains:

<matplotlib.axes._subplots.AxesSubplot object at 0x00000161AB26AE80>

and of course, will give an error if axarr is an array; i.e.

builtins.TypeError: 'AxesSubplot' object does not support indexing

For my code this requires special handling because axarr is no longer an 
array. Why not have axarr contain:

array([<matplotlib.axes._subplots.AxesSubplot object at 

when NSub=1. IMHO this is consistent; i.e. it is an array with a length 
that is equal to the number of subplots.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20180417/cc536d50/attachment.html>

More information about the Matplotlib-users mailing list