<div dir="ltr"><div><div>By default, `squeeze` is called on the array prior to returning it. This way, users don't need to deal with 2D arrays when most of the time, they are dealing with 1D setups. You can specify squeeze=False to subplots to turn this behavior off and always have a 2D array.<br><br></div>I hope that helps!<br></div>Ben Root<br><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Apr 17, 2018 at 10:12 AM, Virgil Stokes <span dir="ltr"><<a href="mailto:vs@it.uu.se" target="_blank">vs@it.uu.se</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div text="#000000" bgcolor="#FFFFFF">
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 data:
<br>
<br>
<tt>fig, axarr = plt.subplots(NSub, figsize=(width,height),
sharex=True)
</tt><br>
<br>
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:
<br>
<br>
<tt> array([<matplotlib.axes._subpl<wbr>ots.AxesSubplot object at
0x0000025900E9DDD8>,
</tt><tt><br>
</tt><tt> <matplotlib.axes._subplots.Axe<wbr>sSubplot object
at 0x00000259011897F0>,
</tt><tt><br>
</tt><tt> <matplotlib.axes._subplots.Axe<wbr>sSubplot object
at 0x00000259011C7128>],
</tt><tt><br>
</tt><tt> dtype=object)
</tt><br>
<br>
However, when NSub=1, axarr contains:
<br>
<br>
<tt><matplotlib.axes._subplots.Axe<wbr>sSubplot object at
0x00000161AB26AE80> <br>
<br>
and of course, will give an error if axarr is an array; i.e.<br>
<br>
</tt><tt><span style="font-size:large;font-weight:600;color:#000066">builtins.TypeError: 'AxesSubplot' object does
not support indexing</span> </tt><br>
<br>
For my code this requires special handling because axarr is no
longer an array. Why not have axarr contain:
<br>
<br>
<tt> array([<matplotlib.axes._subpl<wbr>ots.AxesSubplot object at
0x00000161AB26AE80>],dtype=obj<wbr>ect)
</tt><br>
<br>
when NSub=1. IMHO this is consistent; i.e. it is an array with a
length that is equal to the number of subplots.
</div>
<br>______________________________<wbr>_________________<br>
Matplotlib-users mailing list<br>
<a href="mailto:Matplotlib-users@python.org" target="_blank">Matplotlib-users@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/matplotlib-users" rel="noreferrer" target="_blank">https://mail.python.org/mailma<wbr>n/listinfo/matplotlib-users</a><br>
<br></blockquote></div><br></div></div>