为了账号安全,请及时绑定邮箱和手机立即绑定

如何使线图出现在同一个图形而不是不同的图形上?

如何使线图出现在同一个图形而不是不同的图形上?

鸿蒙传说 2021-06-07 05:27:42
我有一个数据框如下:data = {'Contact':['Email', 'SMS', 'Email', 'Other', 'In Person', 'Other', 'SMS', 'Other', 'Phone', 'Email', 'Other', 'Phone',                    'Phone', 'In Person', 'Email', 'Email', 'Other', 'Other', 'Other', 'Phone', 'Other', 'Email', 'Other',                    'Other'],        'Age': [34, 50, 30, 43, 38, 43, 26, 37, 30, 30, 34, 38, 48, 30, 46, 37, 29, 36, 31, 31, 53, 25, 37, 25]}data = pd.DataFrame(data, columns=['Contact', 'Age'])data我想将Age列分成 10 组,然后将每个组的百分比绘制为线图,分别为每个唯一Contact值。由于 中有 5 个唯一值Contact,它们是'Email', 'SMS', 'Other', 'In Person', 'Phone',因此我希望有 1 个图,其中应该有 5 条线,每条线对应于每个唯一Contact值。但我得到以下信息:contacts = data['Contact'].unique()for c in contacts:    df = data[data['Contact']==c]    y,binEdges=np.histogram(df['Age'], bins=10)    y = 100*y/sum(y)    bincenters = 0.5*(binEdges[1:]+binEdges[:-1])    plt.plot(bincenters,y,label=c)    plt.xlabel('Age')    plt.ylabel('Percentage count')    plt.show()
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 140 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号