dooms
dooms

Reputation: 1645

Plot lines from pandas dataframe

I have a pandas dataframe, and I want to plot for each column a line, from the origin to the point (a,b)

df = pd.DataFrame(data=[[1,2], [7,3]], columns=['a', 'b'])
df.head(10)
df.plot(kind='line')

Here the plot that I get

But I want 2 lines, one from (0,0) to (1,2) and the second from (0,0) to (7,3).

Upvotes: 1

Views: 1873

Answers (1)

VlS
VlS

Reputation: 586

Something like this:

import matplotlib.pylab as pl

for i in range(0, 2):
    pl.plot([0, df.iloc[i][0]], [0,df.iloc[i][1]], label=(i+1))
pl.legend(loc='upper left')
pl.show()

It's not elegant but it works.

enter image description here

Upvotes: 2

Related Questions