I have a list with pandas dataframes each comprising a timeseries.
When I try to plot them in a grid I get them all appearing in the same plot instead (i.e. not in a grid each one occupying a cell of the grid). My code is here:
for i in range(len(building_ids)): # building_ids is the list containing the dataframes/timeseries)
ax = fig.add_subplot(nrows, ncols, i+1)
building_id_dfs[i].plot(label = str(building_ids[i]))
plt.legend()
This returns the following plot:
Another attempt also fails:
fig, axs = plt.subplots(3, 4)
for i in range(nrows):
for j in range(ncols):
axs[i+1, j+1].plot(building_id_dfs[i + j].index, building_id_dfs[i + j], label = str(building_ids[i + j]))
plt.legend()
No handles with labels found to put in legend.
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
<ipython-input-93-2cc113304bb7> in <module>
3 for j in range(ncols):
4
----> 5 axs[i+1, j+1].plot(building_id_dfs[i + j].index, building_id_dfs[i + j], label = str(building_ids[i + j]))
6 plt.legend()
IndexError: index 3 is out of bounds for axis 0 with size 3
How can I solve this issue?


