简体   繁体   中英

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')

这是我得到的情节

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

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.

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM