def plot_openness_by_hour(data: list, period: dict, ax: Axes):
    """
    Plots the openness by hour from the raw data.

    :param data: Raw data
    :param period: Period over which to average the openness
    :param ax: Axes object in which to put the plot
    :return: None
    """
    num_hrs = 24

    # Get data
    hour_bins = get_openness_by_hour(data, period)

    # Plot bar chart
    ax.bar(range(num_hrs + 1), hour_bins)

    # Decorate the axes
    ax.yaxis.grid(True, which="both", linestyle="-.")
    ax.set_xlim(1, num_hrs)
    ax.set_xticks(range(num_hrs + 1))
    ax.set_xticklabels([f"{t:02d}" for t in ax.get_xticks()])
    ax.set_yticklabels([f"{o * 100:.1f}{percent()}" for o in ax.get_yticks()])
    ax.set_ylabel("Andel åpen")
    ax.set_xlabel("Tid på døgnet")
def plot_openness_by_weekday_by_semester(period: dict, ax: Axes):
    """
    Plot openness by semester.

    :param period: Period over which to average the openness
    :param ax: Axes object in which to put the plot
    :return: None
    """
    # Configuration
    num_weekdays = 5
    init_year = 2015
    init_semester = "Vår"

    # Get data for plot
    dataseries = get_openness_by_weekday_by_semester(period)
    num_series = len(dataseries)
    bar_width = 1 / (num_series + 1)

    # Create plot
    cur_year = init_year
    cur_semester = init_semester
    legend = []
    for semester_index, week_bins in enumerate(dataseries):
        # Add bars
        ax.bar(
            [
                weekday_index + semester_index * bar_width
                for weekday_index in range(num_weekdays)
            ],
            height=week_bins[:num_weekdays],
            width=bar_width,
        )

        # Add to legend
        legend.append(f"{cur_semester} {cur_year}")

        # Update semester and year for next bars
        if cur_semester == "Høst":
            cur_semester = "Vår"
            cur_year += 1
        else:
            cur_semester = "Høst"

    # Place legend and labels
    ax.legend(legend, loc="lower right")
    ax.set_xticklabels(("", "Mandag", "Tirsdag", "Onsdag", "Torsdag", "Fredag"))
    ax.set_yticklabels(
        [f"{openness * 100:.1f}{percent()}" for openness in ax.get_yticks()]
    )
    ax.set_ylabel("Andel åpen")
def plot_openness(data: list, period: dict, ax: Axes):
    """
    Plots the openness from the raw data.

    :param data: Raw data
    :param period: Period over which to average the openness
    :param ax: Axes object in which to put the plot
    :return: None
    """
    # Get data
    datetimes, openness = get_openness(data, period)

    # Make filled line plot
    ax.fill_between(datetimes, openness)

    # Decorate axes
    ax.xaxis.set_major_locator(MonthLocator((1, 4, 7, 10), bymonthday=1))
    ax.xaxis.set_major_formatter(DateFormatter("%b '%y"))
    ax.set_yticklabels([f"{o * 100:.0f}{percent()}" for o in ax.get_yticks()])
    ax.set_ylabel("Andel åpen")
    ax.grid(linestyle="-.")
def plot_openness_by_weekday(data: list, period: dict, ax: Axes):
    """
    Plot the openness by weekday from the raw data.

    :param data: Raw data
    :param period: Period over which to average the openness
    :param ax: Axes object in which to put the plot
    :return: None
    """
    week_bins = get_openness_by_weekday(data, period)
    weekday_avg = sum(week_bins[0:5]) / 5
    weekend_avg = sum(week_bins[5:7]) / 2

    # Plot bar
    ax.bar(range(7), week_bins)

    # Plot averages
    ax.text(
        2,
        weekday_avg * 1.05,
        f"Gjennomsnitt ukedager: {weekday_avg * 100:.0f}{percent()}",
    )
    ax.text(
        4.5,
        weekend_avg * 1.1,
        f"Gjennomsnitt helgedager: {weekend_avg * 100:.0f}{percent()}",
    )
    ax.plot((0, 5 - 1), (weekday_avg, weekday_avg), "k--")
    ax.plot((5, 7 - 1), (weekend_avg, weekend_avg), "k--")

    # Decorate axes
    ax.set_xticklabels(
        ("", "Mandag", "Tirsdag", "Onsdag", "Torsdag", "Fredag", "Lørdag", "Søndag")
    )
    ax.set_yticklabels(
        [f"{openness * 100:.1f}{percent()}" for openness in ax.get_yticks()]
    )
    ax.set_ylabel("Andel åpen")