<jupyter_start><jupyter_text>Using matplotlib with timeseries:- Many python workpackages have specific options for timeseries but here we learn how to use matplotlib<jupyter_code>import matplotlib.pyplot as plt
%matplotlib inline<jupyter_output><empty_output><jupyter_text>Use a "top-down" approach- Create a figure (you may add options such as the size of your figure)- Create one or more subplots (here one subplot only): the first argument represents the plot "number" in a grid nrows=1 and ncols=1 (so one subplot only...)<jupyter_code>fig = plt.figure()
ax = fig.add_subplot(1,1,1)
ax.set_title("Plotting timeseries")<jupyter_output><empty_output><jupyter_text>Plot timeseries- define nao_index a vector of real values- define dates using datetime- make sure you define you x-axis as dates so it can be formatted (automatically) as a date- customize your dates so they are human readable; here we chose to rotate x labels (with an angle of 45 degrees) and changed the font size<jupyter_code>nao_index = [0.1234, 0.234, 0.45, -0.2, -0.6]
import datetime
dates = [datetime.date(2001,6,1), datetime.date(2001,6,2), datetime.date(2001,6,3), datetime.date(2001,6,4), datetime.date(2001,6,5)]
print(nao_index)
print(dates)
fig = plt.figure()
ax = fig.add_subplot(1,1,1)
ax.set_title("Plotting timeseries")
ax.set_xticks(dates)
ax.set_xticklabels(dates, rotation=45, fontsize=10)
ax.plot(dates,nao_index)<jupyter_output>[0.1234, 0.234, 0.45, -0.2, -0.6]
[datetime.date(2001, 6, 1), datetime.date(2001, 6, 2), datetime.date(2001, 6, 3), datetime.date(2001, 6, 4), datetime.date(2001, 6, 5)]
{'fraction_non_alphanumeric': 0.12287334593572778, 'fraction_numerical': 0.06679269061121614, 'mean_word_length': 6.057777777777778, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '417592', 'license': 'CC-BY-4.0', 'n_tokens_mistral': 619, 'n_tokens_neox': 551, 'n_words': 173, 'path': 'code/plotting_timeseries.ipynb', 'repo_name': 'uio-carpentry/2017-09-29-geopython', 'size': '1587'}