简体   繁体   中英

Plot two columns based on values in another column

I have a dataframe like follows:

df = pd.DataFrame({'year': [1,2,3],
                    'number' :[4,5,6],
                    'points': [10000,20000,30000]})

What is the easiest way to plot a figure that shows the relationship between number and points in each year? (ie, x-axis is "number" , y-axis is "points" and legend is "year")

I like using holoviews, you can use hvplot ( https://hvplot.holoviz.org/ ) for this:

import hvplot.pandas
df = pd.DataFrame({'year': [1,2,3],
                    'number' :[4,5,6],
                    'points': [10000,20000,30000]})
df.hvplot.scatter(x='number', y='points', color='year', clabel='year')

output:

在此处输入图像描述

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