I am plotting columns of a pandas dataframe in subplots. Which columns to plot is stored in an array, an
. The below code works fine if len(an)>1
, i.e. if I plot more than one graph,
fig, axs = plt.subplots(len(an))
for index, item in enumerate(an, start=0):
gd.plot(ax=axs[index],x="Date",y=item)
but it fails with the error
TypeError: 'AxesSubplot' object is not subscriptable
if len(an)==1
.
Is it possible to make subplots work, if there is just a single plot to plot, or do I have to treat this case separately with an if
?