-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxkcd.py
More file actions
35 lines (27 loc) · 751 Bytes
/
xkcd.py
File metadata and controls
35 lines (27 loc) · 751 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import matplotlib.pyplot as plt
import numpy as np
with plt.xkcd():
# Based on "Stove Ownership" from XKCD by Randall Munroe
# http://xkcd.com/418/
fig = plt.figure()
ax = fig.add_axes((0.1, 0.2, 0.8, 0.7))
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')
plt.xticks([])
plt.yticks([])
# ax.set_ylim([-30, 10])
x = np.arange(-np.pi, +np.pi, 0.1)
y = np.sin(x)
# data = np.ones(100)
# data[70:] -= np.arange(30)
plt.plot(x, y)
plt.annotate(
'x ≈ y',
xy=(0, 0), arrowprops=dict(arrowstyle='->'), xytext=(-1, 0.5))
plt.xlabel('x')
plt.ylabel('sin(x)')
fig.text(
0.5, 0.05,
'XKCD Sin',
ha='center')
plt.show()