自学Python Bokeh 单系列柱状图(纵向 横向)

    xiaoxiao2022-07-02  112

    单系列柱状图

    实战:

    from bokeh.plotting import figure, show, output_file from bokeh.layouts import row output_file("line.html") #单系列柱状图 p1 = figure(plot_width=1200, plot_height=600,x_range='ABC',y_axis_type='linear') # 长 / 高 / 明确X轴为时间格式 / Y轴也可以设置 y_axis_type /y_range # 并且X / Y 轴type只包含('linear', 'log', 'datetime', 'mercator')这几种 p1.xaxis.axis_label = 'type' #X轴标签 p1.yaxis.axis_label = 'number' #Y轴标签 p1.vbar(x=['A','B','C'],width=0.5, bottom=0, top=[10,56,799], # x:横轴坐标,width:宽度,bottom:底高度,top:顶高度 ; bottom=[1,2,3] line_width=0.5, line_alpha=0.8, line_color='black', line_dash=[5,2], #条形图虚线粗细 条形图虚线透明度 条形图虚线颜色 条形图虚线密度 fill_color='red', fill_alpha=0.6) #填充颜色 填充颜色透明度 p2 = figure(plot_width=1200, plot_height=600,x_axis_type='linear',y_range='ABC') p2.xaxis.axis_label = 'type' #X轴标签 p2.yaxis.axis_label = 'number' #Y轴标签 p2.hbar(y=['A','B','C'], height=0.5, left=0,right=[10,56,799], # y:纵轴坐标,height:厚度,left:左边最小值,right:右边最大值 color = ['#0000FF','#8A2BE2','#6495ED'])#颜色一一对应 show(row(p2,p1))

    函数分解含义:

    figure()建立图像底层 plot_width 长度 plot_height 高度 x_range X轴是范围值 也可以是字符串列表 x_axis_type X轴是种类值 只包含(‘linear’, ‘log’, ‘datetime’, ‘mercator’)这几种

    .xaxis.axis_label X轴标签 .yaxis.axis_label Y轴标签

    vbar() 单系列柱状图竖向排列 hbar() 单系列柱状图横向排列

    例: .vbar(x=横轴坐标,width=宽度, bottom=底高度, top=顶高度, line_width=条形图虚线粗细, line_alpha=条形图虚线透明度, line_color=条形图虚线颜色, line_dash=条形图虚线密度, fill_color=填充颜色, fill_alpha=填充颜色透明度)

    例: .hbar(y=纵轴坐标, height=厚度, left=左边最小值,right=右边最大值, color = [颜色号列表,与Y轴各个维度条形图一一对应颜色])

    最新回复(0)