def plot(masking: "Masking", mplot: plt) -> plt:
    """
    Plot layer wise density bar plot.

    :param masking: Masking instance
    :type masking: sparselearning.core.Masking
    :param mplot: matplotlib object
    :type mplot: pyplot
    :return: matplotlib plot
    :rtype: pyplot
    """

    density_ll = _get_density_ll(masking)
    bin_ll = np.arange(len(density_ll)) + 1
    width = 0.8

    mplot.clf()
    mplot.bar(bin_ll, density_ll, width, color="b")

    # Gets too crowded when including layer names
    # layer_name_ll = list(masking.masks.keys())
    # plt.xticks(bin_ll, layer_name_ll)

    mplot.ylabel("Density")
    mplot.xlabel("Layer Number")

    return mplot
示例#2
0
def plot_choice(num: int, plot: plt, df1: pd.DataFrame) -> None:
    """
    Function to re-draw the canvas
    :param num: int of the RadioButton selection
    :param plot: plt Matplotlib.pyplot instance
    :param df1: pd.DataFrame of the TSA data
    :return: None
    """
    plot.clf()
    blue = "#327ff6"
    gray = "#bdb8b6"
    if num == 1:
        # Daily raw pax numbers
        fig, axis = plt.subplots()
        axis.plot(df1['Date'], df1['2020'], color=blue, linestyle='-', label="2020")
        axis.plot(df1['Date'], df1['2019'], color=gray, linestyle='-', label="2019")
        plot.legend()
        plot.xlabel('Date')
        plot.ylabel('Passengers')
        plot.title('TSA Passenger Daily Throughput 2019 and 2020')
        axis.get_yaxis().set_major_formatter(FuncFormatter(lambda x, p: format(int(x), ',')))

        plot_new_canvas(fig, root)

    elif num == 2:
        # Weekly raw pax numbers
        weekly_data = df1.resample('W-Mon', label='right', closed='right',
                                   on='Date').sum().reset_index().sort_values(by='Date')
        fig, axis = plt.subplots()
        axis.plot(weekly_data['Date'], weekly_data['2020'], color=blue, linestyle='-',
                  label="2020")
        axis.plot(weekly_data['Date'], weekly_data['2019'], color=gray, linestyle='-',
                  label="2019")
        axis.get_yaxis().set_major_formatter(FuncFormatter(lambda x, p: format(int(x), ',')))
        plot.xlabel('Date')
        plot.ylabel('Passengers')
        plot.legend()
        plot.ylim(0, 20E6)
        plot.title('TSA Passenger Weekly Throughput 2019 and 2020')

        plot_new_canvas(fig, root)

    elif num == 3:
        # Daily YoY percentage
        fig, axis = plt.subplots()
        axis.plot(df1['Date'], df1['yoy'], color=blue, linestyle='-', label="2020")
        plot.legend()
        plot.xlabel('Date')
        plot.ylabel('Passenger Load Factor (%)')
        plot.title('TSA Passenger Daily Throughput in 2020 as a Percentage of 2019')

        plot_new_canvas(fig, root)

    elif num == 4:
        # Weekly YoY percentage
        weekly_data = df1.resample('W-Mon', label='right', closed='right',
                                   on='Date').sum().reset_index().sort_values(by='Date')
        weekly_data['yoy'] = (weekly_data['2020']/weekly_data['2019'])*100
        fig, axis = plt.subplots()
        axis.plot(weekly_data['Date'], weekly_data['yoy'], color=blue, linestyle='-',
                  label="2020")
        plot.xlabel('Date')
        plot.ylabel('Passenger Load Factor (%)')
        plot.legend()
        plot.title('TSA Passenger Daily Throughput in 2020 as a Percentage of 2019')

        plot_new_canvas(fig, root)