首页 > 解决方案 > Matplotlib:每条线具有不同组的折线图

问题描述

例如这张表:

list_1=[['2010','20-30',0.2],
        ['2010','31-40',0.35],
       ['2010','41-50',0.47,],
       ['2010','51-60',0.21,],
       ['2011','20-30',0.23,],
       ['2011','31-40',0.42,],
       ['2011','41-50',0.55,],
       ['2011','51-60',0.19,],
       ['2012','20-30',0.36,],
       ['2012','31-40',0.24,],
       ['2012','41-50',0.71,],
       ['2012','51-60',0.12,]]
labels=['Year','Age_group','Order_Rate']
df=pd.DataFrame(list_1,columns=labels)
df

输出:

    Year    Age_group   Order_Rate
0   2010    20-30       0.20
1   2010    31-40       0.35
2   2010    41-50       0.47
3   2010    51-60       0.21
4   2011    20-30       0.23
5   2011    31-40       0.42
6   2011    41-50       0.55
7   2011    51-60       0.19
8   2012    20-30       0.36
9   2012    31-40       0.24
10  2012    41-50       0.71
11  2012    51-60       0.12

我需要制作 x_axis= Year, y_axis= Order_Rate 和此 Age_Group 的每种颜色趋势线的折线图

标签: pythonpandasmatplotlibplotanalytics

解决方案


推荐阅读