def draw_additive_plot(data, figsize, show, text_rotation=0):
    """Draw additive plot."""
    # Turn off interactive plot
    if show == False:
        plt.ioff()
    
    # Format data
    neg_features, total_neg, pos_features, total_pos = format_data(data)
    
    # Compute overall metrics
    base_value = data['baseValue']
    out_value = data['outValue']
    offset_text = (np.abs(total_neg) + np.abs(total_pos)) * 0.04
    
    # Define plots
    fig, ax = plt.subplots(figsize=figsize)
    
    # Compute axis limit
    update_axis_limits(ax, total_pos, pos_features, total_neg,
                       neg_features, base_value)
    
    # Define width of bar
    width_bar = 0.1
    width_separators = (ax.get_xlim()[1] - ax.get_xlim()[0]) / 200
    
    # Create bar for negative shap values
    rectangle_list, separator_list = draw_bars(out_value, neg_features, 'negative',
                                               width_separators, width_bar)
    for i in rectangle_list:
        ax.add_patch(i)
    
    for i in separator_list:
        ax.add_patch(i)
    
    # Create bar for positive shap values
    rectangle_list, separator_list = draw_bars(out_value, pos_features, 'positive',
                                               width_separators, width_bar)
    for i in rectangle_list:
        ax.add_patch(i)
    
    for i in separator_list:
        ax.add_patch(i)

    # Add labels
    total_effect = np.abs(total_neg) + total_pos
    fig, ax = draw_labels(fig, ax, out_value, neg_features, 'negative',
                          offset_text, total_effect, min_perc=0.05, text_rotation=text_rotation)
    
    fig, ax = draw_labels(fig, ax, out_value, pos_features, 'positive',
                          offset_text, total_effect, min_perc=0.05, text_rotation=text_rotation)
    
    # higher lower legend
    draw_higher_lower_element(out_value, offset_text)
    
    # Add label for base value
    draw_base_element(base_value, ax)
    
    # Add output label
    out_names = data['outNames'][0]
    draw_output_element(out_names, out_value, ax)
    
    if show:
        plt.show()
    else:
        return plt.gcf()
def draw_additive_plot ( data , figsize , show , text_rotation = 0 ) : if show == False : plt . ioff ( ) neg_features , total_neg , pos_features , total_pos = format_data ( data ) base_value = data [ 'baseValue' ] out_value = data [ 'outValue' ] offset_text = ( np . abs ( total_neg ) + np . abs ( total_pos ) ) * 0.04 fig , ax = plt . subplots ( figsize = figsize ) update_axis_limits ( ax , total_pos , pos_features , total_neg , neg_features , base_value ) width_bar = 0.1 width_separators = ( ax . get_xlim ( ) [ 1 ] - ax . get_xlim ( ) [ 0 ] ) / 200 rectangle_list , separator_list = draw_bars ( out_value , neg_features , 'negative' , width_separators , width_bar ) for i in rectangle_list : ax . add_patch ( i ) for i in separator_list : ax . add_patch ( i ) rectangle_list , separator_list = draw_bars ( out_value , pos_features , 'positive' , width_separators , width_bar ) for i in rectangle_list : ax . add_patch ( i ) for i in separator_list : ax . add_patch ( i ) total_effect = np . abs ( total_neg ) + total_pos fig , ax = draw_labels ( fig , ax , out_value , neg_features , 'negative' , offset_text , total_effect , min_perc = 0.05 , text_rotation = text_rotation ) fig , ax = draw_labels ( fig , ax , out_value , pos_features , 'positive' , offset_text , total_effect , min_perc = 0.05 , text_rotation = text_rotation ) draw_higher_lower_element ( out_value , offset_text ) draw_base_element ( base_value , ax ) out_names = data [ 'outNames' ] [ 0 ] draw_output_element ( out_names , out_value , ax ) if show : plt . show ( ) else : return plt . gcf ( )
Draw additive plot.