How do I plot multiple line in 1 graph from multiple data in dataframe

Viewed 16

I made some data in dataframe and I wanted to plot them into 1 graph, how do I do that?

I plot them one by one using these codes and here are the results

df.plot(x='MONTH', y='MONTHLY INCOME')
df.plot(x='MONTH', y='MONTHLY EXPENSES')
df.plot(x='MONTH', y='MONTHLY SAVINGS')

graphs https://i.stack.imgur.com/59kpV.png

Dataframe https://i.stack.imgur.com/vPiFO.png

1 Answers

Try using matplotlib.

import matplotlib.pyplot as plt

legend_labels = ['INCOME', 'EXPENSES', 'SAVINGS']
plt.plot(df['MONTH'], df['MONTHLY INCOME'])
plt.plot(df['MONTH'], df['MONTHLY EXPENSES'])
plt.plot(df['MONTH'], df['MONTHLY SAVINGS'])
plt.legend(legend_labels)
plt.show()

Related