Suppose I want to plot 3 graphs in 1 row: dependencies cnt
from other 3 features.
Code:
fig, axes = plt.subplots(nrows=1,
The problem is not related to pandas. The index error you see comes from ax= axes[0, idx]
. This is because you have a single row. [0, idx]
would work when you have more than one row.
For just one row, you can skip the first index and use
fig, axes = plt.subplots(nrows=1, ncols=3, figsize=(15, 10))
for idx, feature in enumerate(min_regressors):
df_shuffled.plot(feature, "cnt", subplots=True, kind="scatter", ax= axes[idx])
plt.show()
As a recap
Correct
fig, axes = plt.subplots(nrows=1, ncols=3, figsize=(8, 3))
axes[0].plot([1,2], [1,2])
Incorrect
fig, axes = plt.subplots(nrows=1, ncols=3, figsize=(8, 3))
axes[0, 0].plot([1,2], [1,2])
Correct
fig, axes = plt.subplots(nrows=2, ncols=3, figsize=(8, 3))
axes[0,0].plot([1,2], [1,2])