I am trying to plot three data frames in three columns using matplpotlib. I am plotting each column of a DF as a subplot in the respective column of the figure. But the plot seems to overlap with each other. Not sure what is going wrong. Please help me find the issue. Thanks.
I added the code below I tried to achieve what I mentioned above. I did not define a number of rows and columns in subplot since I wanted to create based on the number of columns in DF. Then I used add_subplot function to add each one them in for loop. But subplots are overlapping in the output. I tried fig.tightlayout based on suggestions from other post but I got UserWarning: tight_layout not applied: a number of rows in subplot specifications must be multiples of one another
fig = plt.figure()
#looping through each DF in a dict
for df_count, df_name in enumerate(df_dict):
df = df_dict[df_name]
#looping through column in the DF
for col_count, col in enumerate(df_dict[df_name]):
if col != "VAR":
print (col, col_count )
ax = fig.add_subplot(col_count, df_count + 1, 1)
ax.plot(df[col], df["CATEGORY"])
fig.tight_layout()
plt.savefig('foo.png')