0

I want plot the graphs one by one from the dataframe with FOR operator.

names_list = df.columns.tolist()
for name in names_list:
    df[name].plot(figsize=(25, 5))

This code is no good. The graphs are depicted in one figure, but should be in different ones. enter image description here

How can I get multiple charts instead of one?

2 Answers 2

1

Try the following:

names_list = df.columns.tolist()
for name in names_list:
    fig, ax = plt.subplots(figsize=(25, 5)) 
    df[name].plot(ax=ax)
Sign up to request clarification or add additional context in comments.

Comments

1

If you're able to use seaborn here's an example using a FacetGrid:

import seaborn as sns, matplotlib.pyplot as plt

In [102]: df.head(3)
Out[102]: 
        Date  Consumption  Wind  Solar  Wind+Solar  name
0 2006-01-01     1069.184   NaN    NaN         NaN   mid
1 2006-01-02     1380.521   NaN    NaN         NaN   mid
2 2006-01-03     1442.533   NaN    NaN         NaN  high

g = sns.FacetGrid(data=df,col='name',col_wrap=1,hue='name')
g.fig.set_size_inches(6,3) # compressed just to show example
g.map(sns.lineplot,'Date','Consumption')
plt.show()

Result:

enter image description here

2 Comments

Plots of all columns of a dataframe are required, but not one. But thanks for the option. It will be useful to me too.
Ah, I see. I'm glad the other answer helped you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.