<jupyter_start><jupyter_text>Helper functions<jupyter_code>def number_formatter(number, pos=None):
    """Convert a number into a human readable format.
    
    Via https://flynn.gg/blog/better-matplotlib-charts/"""
    magnitude = 0
    while abs(number) >= 1000:
        magnitude += 1
        number /= 1000.0
    return "€%.0f %s" % (number, ["", "K", "M", "B", "T", "Q"][magnitude])
def draw_bands(ax, ticks=None):
    """Add grey bands to the plot.

    Args:
        ax: a matplotlib axes object.
        ticks: a list of tick postions, to use instead of the ones that come
            with ax.
    """
    if ticks is None:
        ticks = ax.get_xticks(minor=False)

    for i in range(0, len(ticks), 2):
        # Check for the end of the array
        if i >= len(ticks) or i + 1 >= len(ticks):
            return

        # Draw a band
        left_tick = ticks[i]
        right_tick = ticks[i + 1]
        plt.axvspan(left_tick, right_tick, color="0.97", zorder=-2)
def draw_legend(plt):
    """Draw the legend on the specified plot.

    Args:
        plt (matplotlib.pyplot): pyplot object
    """
    leg = plt.legend(
        loc="upper left",
        fontsize=24,
        ncol=1,
        frameon=1,
        fancybox=True,
        # The bellow commands remove the lines in the legend
        handlelength=0,
        handletextpad=0,
        markerscale=0,
    )

    # Turn on and theme the frame
    frame = leg.get_frame()
    frame.set_linewidth(1.2)
    frame.set_alpha(1)
    frame.set_facecolor("white")
    frame.set_edgecolor("black")

    # Set the legend text color to match the line color
    lines = leg.get_lines()
    texts = leg.get_texts()
    for line, text in zip(lines, texts):
        text.set_color(line.get_color())<jupyter_output><empty_output><jupyter_text>Load the data<jupyter_code>df = pd.read_json("./data/tdf_prizes_dataframe.json", orient="table")
x = df.index
y_tot = df["total_adjusted_euro"]
y_first = df["first_prize_adjusted_euro"]<jupyter_output><empty_output><jupyter_text>Make the plot<jupyter_code>fig, ax = plt.subplots(figsize=(WIDTH, HEIGHT))

# Plot the data
LINEWIDTH = 3
STEP_WHERE = "post"
plt.step(x, y_tot, where=STEP_WHERE, linewidth=LINEWIDTH, label="Total prize money")
plt.step(x, y_first, where=STEP_WHERE, linewidth=LINEWIDTH, label="Winner's prize money")

plt.yscale("log")

# Set titles
plt.figtext(0.5, 0.95, "Tour de France Prize Money", fontsize=34, ha="center")
plt.figtext(0.5, 0.9, "In 2013 Euro", fontsize=24, ha="center")
ax.set_ylabel(None)
ax.set_xlabel(None)

ax.set_xlim("1901", "2015")

ax.tick_params(axis="y", which="major", labelsize=28)
ax.tick_params(axis="x", which="major", labelsize=22)
ax.yaxis.set_major_formatter(FuncFormatter(number_formatter))
ax.yaxis.grid()  # horizontal lines

plt.xticks(ticks=[str(yr) for yr in range(1910, 2020, 20)])
draw_bands(ax, [str(yr) for yr in range(1900, 2020, 10)])

draw_legend(plt)

# Save to disk
for ext in ("png", "svg"):
    fig.savefig(
        "/tmp/tdf_prize_money_in_2013_euro.{ext}".format(ext=ext), bbox_inches="tight"
    )<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1396774193548387, 'fraction_numerical': 0.027096774193548386, 'mean_word_length': 3.4236804564907275, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 16, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '325654', 'license': 'MIT', 'n_tokens_mistral': 1209, 'n_tokens_neox': 1115, 'n_words': 266, 'path': 'files/tdf-prize-money/Tour de France Prize Plot.ipynb', 'repo_name': 'agude/agude.github.io', 'size': '3100'}