notebooks/common.py
def plot_summary_line_by_pollster(df, column, title,
                                  function, argument, lfooter, rot=0):
    """For each pollster, plot a summary line calculated with function()"""
    MINIMUM_POLLS_REQUIRED = 2 # two polls needed for a line
    fig, ax = initiate_plot()
    for i, pollster in enumerate(sorted(df['Brand'].unique())):
        polls = df[df['Brand'] == pollster].copy()
        if len(polls) < MINIMUM_POLLS_REQUIRED:
            continue
        add_summary_line(ax, df=polls, column=column, l_color=None, 
                         function=function, argument=argument, rot=rot)
        add_data_points_by_pollster(ax, df=polls, column=column, p_color=None, marker=MARKERS[i])

    ax.legend(loc='best')
    plot_finalise(ax, 
                  ylabel='Per cent',
                  title=title, 
                  lfooter=lfooter,
                  concise_dates=True)
For each pollster, plot a summary line calculated with function()
For each pollster, plot a summary line calculated with function()
For each pollster plot a summary line calculated with function ()
def plot_summary_line_by_pollster(df, column, title,
                                  function, argument, lfooter, rot=0):
    MINIMUM_POLLS_REQUIRED = 2 
    fig, ax = initiate_plot()
    for i, pollster in enumerate(sorted(df['Brand'].unique())):
        polls = df[df['Brand'] == pollster].copy()
        if len(polls) < MINIMUM_POLLS_REQUIRED:
            continue
        add_summary_line(ax, df=polls, column=column, l_color=None, 
                         function=function, argument=argument, rot=rot)
        add_data_points_by_pollster(ax, df=polls, column=column, p_color=None, marker=MARKERS[i])
    ax.legend(loc='best')
    plot_finalise(ax, 
                  ylabel='Per cent',
                  title=title, 
                  lfooter=lfooter,
                  concise_dates=True)
def plot_summary_line_by_pollster ( df , column , title , function , argument , lfooter , rot = 0 ) : MINIMUM_POLLS_REQUIRED = 2 fig , ax = initiate_plot ( ) for i , pollster in enumerate ( sorted ( df [ 'Brand' ] . unique ( ) ) ) : polls = df [ df [ 'Brand' ] == pollster ] . copy ( ) if len ( polls ) < MINIMUM_POLLS_REQUIRED : continue add_summary_line ( ax , df = polls , column = column , l_color = None , function = function , argument = argument , rot = rot ) add_data_points_by_pollster ( ax , df = polls , column = column , p_color = None , marker = MARKERS [ i ] ) ax . legend ( loc = 'best' ) plot_finalise ( ax , ylabel = 'Per cent' , title = title , lfooter = lfooter , concise_dates = True )
For each pollster, plot a summary line calculated with function()
For each pollster plot a summary line calculated with function ()
"""For each pollster, plot a summary line calculated with function()""" # two polls needed for a line
df
column
title
function
argument
lfooter
rot