<jupyter_start><jupyter_text>Plotting by cell using analysis.csv<jupyter_code>import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
# Need this to get all the cells
tasmax_other = pd.read_csv("tasmax_heatwaves.csv")
tasmax_other = tasmax_other.set_index(["lon", "lat"])

# Store cells in variable
cells = list(np.unique(tasmax_other.index))
analysis = pd.read_csv("analysis.csv", parse_dates=["year"])
analysis = analysis.set_index(["lon", "lat", "year"])
analysis
analysis.loc[-122.75, 42.25].tasmax_num_days.plot()
# Creates all the plots in the folder plots_by_cell
# Create folder plots_by_cell manually before running this function
def create_actual_data_plots():
    for i, cell in enumerate(cells):
        fig, axes = plt.subplots(2, 2, figsize=(8, 11), sharex=True)

        data = analysis.loc[cell]
        rolling = data.rolling(window=5, win_type="exponential")
        rolling_mean = rolling.mean(tau=20)

        axes[0, 0].plot(data.tasmax_num_days, "r", label="Actual")
        axes[0, 0].plot(rolling_mean.tasmax_num_days, "k", label="Rolling mean")
        axes[0, 0].set(title="Tasmax Num Days")
        axes[0, 0].legend()

        axes[0, 1].plot(data.tasmin_num_days, "b", label="Actual")
        axes[0, 1].plot(rolling_mean.tasmin_num_days, "k", label="Rolling mean")
        axes[0, 1].set(title="Tasmin Num Days")
        axes[0, 1].legend()

        axes[1, 0].plot(data.tasmax_max_temp, "r")
        axes[1, 0].plot(rolling_mean.tasmax_max_temp, "k")
        axes[1, 0].set(title="Tasmax Max Temperature", xlabel="Date (2006-2099)")

        axes[1, 1].plot(data.tasmin_max_temp, "b")
        axes[1, 1].plot(rolling_mean.tasmin_max_temp, "k")
        axes[1, 1].set(title="Tasmin Max Temperature", xlabel="Date (2006-2099)")

        axes[1, 0].set_xticks([])
        axes[1, 1].set_xticks([])

        plt.tight_layout()

        fig.suptitle(f"{cell}")
        # Output to the folder plots_by_cell
        plt.savefig(f"plots_by_cell/{cell}.pdf")
        plt.close()
        print(f"Index {i}/{len(cell)-1} worked for {cell}")
create_actual_data_plots()<jupyter_output>Index 0 worked for (-122.75, 42.25)
Index 1 worked for (-119.75, 34.25)
Index 2 worked for (-118.25, 34.75)
Index 3 worked for (-109.75, 31.25)
Index 4 worked for (-106.75, 32.25)
Index 5 worked for (-106.25, 28.75)
Index 6 worked for (-103.25, 25.75)
Index 7 worked for (-102.75, 20.75)
Index 8 worked for (-99.75, 16.75)
Index 9 worked for (-99.75, 17.75)
Index 10 worked for (-98.75, 20.25)
Index 11 worked for (-98.25, 34.75)
Index 12 worked for (-97.75, 25.75)
Index 13 worked for (-97.25, 19.75)
Index 14 worked for (-96.25, 42.25)
Index 15 worked for (-91.25, 14.25)
Index 16 worked for (-90.75, 42.75)
Index 17 worked for (-88.25, 15.25)
Index 18 worked for (-87.75, 42.25)
Index 19 worked for (-85.75, 42.75)
Index 20 worked for (-84.75, 42.75)
Index 21 worked for (-84.25, 33.75)
Index 22 worked for (-79.75, -1.25)
Index 23 worked for (-79.25, 44.25)
Index 24 worked for (-77.75, 21.25)
Index 25 worked for (-76.25, 4.25)
Index 26 worked for (-75.25, 7.75)
Index 27 worked for (-73.75, 18.[...]
{'fraction_non_alphanumeric': 0.16042267050912584, 'fraction_numerical': 0.10854947166186359, 'mean_word_length': 3.475644699140401, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '382553', 'license': 'MIT', 'n_tokens_mistral': 1428, 'n_tokens_neox': 1158, 'n_words': 321, 'path': '5_final_plots/Plotting by Cell.ipynb', 'repo_name': 'codeananda/geographic_data_analysis', 'size': '3123'}