bucketplot.py
def create_bplot(
    df_for_plt, stat_wgt, stat_vars,
    cols=bokeh.palettes.Dark2[8],
):
    """Create bucket plot object from aggregated data"""
    # Set up the figure
    bkp = bokeh.plotting.figure(
        title="One-way plot", x_axis_label="X-axis name", y_axis_label=stat_wgt, 
        tools="reset,box_zoom,pan,wheel_zoom,save", background_fill_color="#fafafa",
        plot_width=800, plot_height=500
    )

    # Plot the histogram squares...
    bkp.quad(
        top=df_for_plt[stat_wgt], bottom=0,
        left=df_for_plt['x_left'], right=df_for_plt['x_right'],
        fill_color="khaki", line_color="white", legend_label="Weight"
    )
    # ...at the bottom of the graph
    bkp.y_range = bokeh.models.ranges.Range1d(
        **expand_lims(df_for_plt[stat_wgt], 0, 1.2, 0)
    )

    bkp.legend.location = "top_left"
    bkp.legend.click_policy="hide"

    # Plot the weight average statistic points joined by straight lines
    # Set up the secondary axis
    bkp.extra_y_ranges['y_range_2'] = bokeh.models.ranges.Range1d(
        **expand_lims(df_for_plt[[stat_var + '_wgt_av' for stat_var in stat_vars]])
    )
    bkp.add_layout(bokeh.models.axes.LinearAxis(
        y_range_name='y_range_2',
        axis_label="Weighted average statistic"
    ), 'right')

    for var_num, stat_var in enumerate(stat_vars):
        # The following parameters need to be passed to both circle() and line()
        stat_line_args = {
            'x': df_for_plt['x_point'],
            'y': df_for_plt[stat_var + '_wgt_av'],
            'y_range_name': 'y_range_2',
            'color': cols[var_num],
            'legend_label': stat_var,
        }
        bkp.circle(**stat_line_args, size=4)
        bkp.line(**stat_line_args)
    
    return(bkp)
Create bucket plot object from aggregated data
Create bucket plot object from aggregated data
Create bucket plot object from aggregated data
def create_bplot(
    df_for_plt, stat_wgt, stat_vars,
    cols=bokeh.palettes.Dark2[8],
):
    bkp = bokeh.plotting.figure(
        title="One-way plot", x_axis_label="X-axis name", y_axis_label=stat_wgt, 
        tools="reset,box_zoom,pan,wheel_zoom,save", background_fill_color="#fafafa",
        plot_width=800, plot_height=500
    )
    bkp.quad(
        top=df_for_plt[stat_wgt], bottom=0,
        left=df_for_plt['x_left'], right=df_for_plt['x_right'],
        fill_color="khaki", line_color="white", legend_label="Weight"
    )
    bkp.y_range = bokeh.models.ranges.Range1d(
        **expand_lims(df_for_plt[stat_wgt], 0, 1.2, 0)
    )
    bkp.legend.location = "top_left"
    bkp.legend.click_policy="hide"
    bkp.extra_y_ranges['y_range_2'] = bokeh.models.ranges.Range1d(
        **expand_lims(df_for_plt[[stat_var + '_wgt_av' for stat_var in stat_vars]])
    )
    bkp.add_layout(bokeh.models.axes.LinearAxis(
        y_range_name='y_range_2',
        axis_label="Weighted average statistic"
    ), 'right')
    for var_num, stat_var in enumerate(stat_vars):
        stat_line_args = {
            'x': df_for_plt['x_point'],
            'y': df_for_plt[stat_var + '_wgt_av'],
            'y_range_name': 'y_range_2',
            'color': cols[var_num],
            'legend_label': stat_var,
        }
        bkp.circle(**stat_line_args, size=4)
        bkp.line(**stat_line_args)
    return(bkp)
def create_bplot ( df_for_plt , stat_wgt , stat_vars , cols = bokeh . palettes . Dark2 [ 8 ] , ) : bkp = bokeh . plotting . figure ( title = "One-way plot" , x_axis_label = "X-axis name" , y_axis_label = stat_wgt , tools = "reset,box_zoom,pan,wheel_zoom,save" , background_fill_color = "#fafafa" , plot_width = 800 , plot_height = 500 ) bkp . quad ( top = df_for_plt [ stat_wgt ] , bottom = 0 , left = df_for_plt [ 'x_left' ] , right = df_for_plt [ 'x_right' ] , fill_color = "khaki" , line_color = "white" , legend_label = "Weight" ) bkp . y_range = bokeh . models . ranges . Range1d ( ** expand_lims ( df_for_plt [ stat_wgt ] , 0 , 1.2 , 0 ) ) bkp . legend . location = "top_left" bkp . legend . click_policy = "hide" bkp . extra_y_ranges [ 'y_range_2' ] = bokeh . models . ranges . Range1d ( ** expand_lims ( df_for_plt [ [ stat_var + '_wgt_av' for stat_var in stat_vars ] ] ) ) bkp . add_layout ( bokeh . models . axes . LinearAxis ( y_range_name = 'y_range_2' , axis_label = "Weighted average statistic" ) , 'right' ) for var_num , stat_var in enumerate ( stat_vars ) : stat_line_args = { 'x' : df_for_plt [ 'x_point' ] , 'y' : df_for_plt [ stat_var + '_wgt_av' ] , 'y_range_name' : 'y_range_2' , 'color' : cols [ var_num ] , 'legend_label' : stat_var , } bkp . circle ( ** stat_line_args , size = 4 ) bkp . line ( ** stat_line_args ) return ( bkp )
Create bucket plot object from aggregated data
Create bucket plot object from aggregated data
"""Create bucket plot object from aggregated data""" # Set up the figure # Plot the histogram squares... # ...at the bottom of the graph # Plot the weight average statistic points joined by straight lines # Set up the secondary axis # The following parameters need to be passed to both circle() and line()
df_for_plt
stat_wgt
stat_vars
cols