. Advertisement .
..3..
. Advertisement .
..4..
I am working with python and getting the error message:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-108-ce962754d553> in <module>()
----> 2 axs[0, 0].boxplot([df1['x'], df2['x']])
3 plt.show();
4
TypeError: 'AxesSubplot' object is not subscriptable
Here is the detail of the code that I ran
fig, axs = plt.subplots()
axs[0, 0].boxplot([df1['x'], df2['x']])
plt.show();
I need an explanation for the problems I’ve encountered. How to fix axessubplot’ object is not subscriptable?
The cause:
Above command returns a figure that has only one subplot, but axs holds it with no indexing.
A 1D array with subplots is returned.
Returns a 2D array with subplots.
This is because the default setting for the kwarg, so the error happens.
Solution:
You can suppress this problem by setting
False
in the.subplots()
command to force it return the result to be a 2-dimensional array, regardless of how many or arrange the subplots.