以下为python语言采用bokeh库对数字类型的age和字符串类型的marital是否已婚x轴字符不重叠鼠标在柱形图上时可以显示具体已婚的数量在一张图可视化分析from bokehplotting import figure showoutput_fileimport numpy as npimport pandas as pdimport pandasdf = pdread_csvrUsers
对marital列进行分组统计
marital_count = df.groupby('marital')['marital'].count()
对age列进行分组统计
age_count = df.groupby('age')['age'].count()
创建柱形图
p = figure(x_range=list(marital_count.index), plot_height=350, title="Marital Status Count", toolbar_location=None, tools="")
添加柱形
p.vbar(x=list(marital_count.index), top=marital_count.values, width=0.9)
添加鼠标悬停提示
p.add_tools(HoverTool(tooltips=[("Marital Status", "@x"), ("Count", "@top")]))
设置x轴标签角度
p.xaxis.major_label_orientation = 0.8
创建柱形图
p2 = figure(x_range=list(age_count.index), plot_height=350, title="Age Count", toolbar_location=None, tools="")
添加柱形
p2.vbar(x=list(age_count.index), top=age_count.values, width=0.9)
添加鼠标悬停提示
p2.add_tools(HoverTool(tooltips=[("Age", "@x"), ("Count", "@top")]))
设置x轴标签角度
p2.xaxis.major_label_orientation = 0.8
显示图表
show(row(p, p2)
原文地址: http://www.cveoy.top/t/topic/e90a 著作权归作者所有。请勿转载和采集!