使用python的bokeh库对housing和default关系可视化分析布局合理from bokehplotting import figure showoutput_fileimport numpy as npimport pandas as pdimport pandasdf = pdread_csvrUsersfuchuanruoDesktop可视化作业实践traincsvtest =
计算housing和default之间的关系
housing_default = df.groupby(['housing', 'default']).size().reset_index(name='counts')
创建绘图空间
p = figure(title="Housing vs Default Relationship", x_range=housing_default['housing'], plot_height=350, plot_width=500)
绘制柱状图
p.vbar(x=housing_default['housing'], top=housing_default['counts'], width=0.9, color=['#FFC107', '#3F51B5'], legend_label=housing_default['default'])
设置图例位置
p.legend.location = "top_left"
设置图例字体大小
p.legend.label_text_font_size = "10pt"
设置x轴标签
p.xaxis.axis_label = 'Housing'
设置y轴标签
p.yaxis.axis_label = 'Counts'
输出到html文件
output_file("housing_default.html")
展示图形
show(p
原文地址: https://www.cveoy.top/t/topic/fbBz 著作权归作者所有。请勿转载和采集!