<jupyter_start><jupyter_text>Plotting in Python: Examples and Exercises First some imports:<jupyter_code>import numpy as np
import matplotlib.pyplot as plt<jupyter_output><empty_output><jupyter_text>Now some examples --- please read this code first.<jupyter_code>x = np.linspace(-6, 6, 200)
y = np.minimum(np.sin(x), np.cos(x))
fig, ax = plt.subplots()
ax.plot(x, y)
plt.show()<jupyter_output><empty_output><jupyter_text>Here's a plot with two curves.<jupyter_code>y1 = np.minimum(np.sin(x), np.cos(x))
y2 = np.maximum(np.sin(x), np.cos(x))
fig, ax = plt.subplots()
ax.plot(x, y1, label='y1')
ax.plot(x, y2, label='y2')
ax.legend()

plt.show()<jupyter_output><empty_output><jupyter_text>Exercise 1 Plot the tent map$$ f(x) = \mu \min\{x, 1 - x\} $$on the interval $[0, 1]$ when $\mu = 1.8$<jupyter_code>for i in range(15):
    print("solution below")
μ = 1.8
x = np.linspace(0, 1, 200)
y = μ * np.minimum(x, 1 - x)
fig, ax = plt.subplots()
ax.plot(x, y)
plt.show()<jupyter_output><empty_output><jupyter_text>Exercise 2 The following example makes an empty array of length 3 and then fills them with the numbers 0.5, 1.0, 0.5:<jupyter_code>x = np.empty(3)
x[0] = 0.5
x[1] = 1.0
x[2] = 0.5
x<jupyter_output><empty_output><jupyter_text>The next code shows what the `range()` function does:<jupyter_code>for i in range(5):
    print(i)<jupyter_output>0
1
2
3
4<jupyter_text>Now compute the time series of length 500 given by$$ x_{t+1} = f(x_t) $$where $f$ is as given above and $x_0 = 0.2$.  Plot $x_t$ against $t$.<jupyter_code>for i in range(15):
    print("solution below")
n = 500
x = np.empty(n)
x[0] = 0.2
for t in range(n-1):
    x[t+1] = μ * min(x[t], 1 - x[t])
fig, ax = plt.subplots()
ax.plot(range(n), x)
plt.show()<jupyter_output><empty_output><jupyter_text>Exercise 3 The next code shows how to build a histogram.<jupyter_code>z = np.random.randn(1000)
fig, ax = plt.subplots()
ax.hist(z, bins=40)
plt.show()<jupyter_output><empty_output><jupyter_text>Now recompute the time series from the tent map, this time with $n=500,000$, and histogram it.<jupyter_code>for i in range(15):
    print("solution below")
n = 1_000_000
x = np.empty(n)
x[0] = 0.2
for t in range(n-1):
    x[t+1] = μ * min(x[t], 1 - x[t])
fig, ax = plt.subplots()
ax.hist(x, bins=40)
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1703607127335941, 'fraction_numerical': 0.04302477183833116, 'mean_word_length': 5.010443864229765, 'pattern_counts': {'":': 0, '<': 36, '<?xml version=': 0, '>': 36, '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': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '660061', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1059, 'n_tokens_neox': 984, 'n_words': 249, 'path': 'John/plots.ipynb', 'repo_name': 'snowdj/phd_workshops', 'size': '2301'}