from bokeh.plotting import figure, show, output_file import numpy as np import pandas as pd import pandas df = pd.read_csv(r'/Users/fuchuanruo/Desktop/可视化作业/实践/train.csv') test = pd.read_csv(r'/Users/fuchuanruo/Desktop/可视化作业/实践/test.csv')

计算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)

Housing and Default Relationship Visualization using Bokeh in Python

原文地址: https://www.cveoy.top/t/topic/jjX2 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录