1

I have a dataframe with a datetime-index and 65 columns.
And I want to plot all these colums among themselves, not in a grid or in one figure.

df= test[['one', 'two', 'three','four']]
fig, ax = plt.subplots(figsize=(24, 5))
df.plot(ax=ax)
plt.show()

The example is all in one plot and not all among themselves.

4
  • What does "among themselves" mean? Can you explain that in your own words? Commented Jun 23, 2019 at 21:51
  • so that every chart has only one graph Commented Jun 23, 2019 at 22:16
  • 1
    Do you mean df.plot(subplots=True)? Commented Jun 23, 2019 at 22:35
  • possible duplicate of this: stackoverflow.com/questions/55567706/… Commented Dec 16, 2019 at 10:19

1 Answer 1

2

You can loop over the columns of the DataFrame and create a new figure for each column. This will plot them all at once. If you want the next one to show up once the previous one is closed then put the call to plt.show() inside the for loop.

import pandas as pd 
import matplotlib.pyplot as plt 


df = pd.DataFrame({
        'one': [1, 3, 2, 5],
        'two': [9, 6, 4, 3],
        'three': [0, 1, 1, 0],
        'four': [-3, 2, -1, 0]})

for i, col in enumerate(df.columns):
    df[col].plot(fig=plt.figure(i))
    plt.title(col)

plt.show()
Sign up to request clarification or add additional context in comments.

Comments

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.