-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path08_plotannotate.py
More file actions
60 lines (41 loc) · 1.42 KB
/
08_plotannotate.py
File metadata and controls
60 lines (41 loc) · 1.42 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import numpy as np
import matplotlib.pyplot as plt
# if using a Jupyter notebook, include:
# %matplotlib inline
x = np.arange(-5, 5, 0.01)
y = x**2
fig, ax = plt.subplots()
# Plot a line
ax.plot(x, y)
# first annotation relative to the data
ax.annotate('function minium \n relative to data',
xy=(0, 0),
xycoords='data',
xytext=(2, 3),
arrowprops=
dict(facecolor='black', shrink=0.05),
horizontalalignment='left',
verticalalignment='top')
# second annotation relative to the axis limits
bbox_props = dict(boxstyle="round,pad=0.5", fc="w", ec="k", lw=2)
ax.annotate('half of range \n relative to axis limits',
xy=(0, 0.5),
xycoords='axes fraction',
xytext=(0.2, 0.5),
bbox=bbox_props,
arrowprops=
dict(facecolor='black', shrink=0.05),
horizontalalignment='left',
verticalalignment='center')
# third annotation relative to the figure window
bbox_props = dict(boxstyle="larrow,pad=0.5", fc="w", ec="k", lw=2)
ax.annotate('outside the plot \n relative to figure window',
xy=(20, 75),
xycoords='figure pixels',
horizontalalignment='left',
verticalalignment='top',
bbox=bbox_props)
ax.set_xlim(-5,5)
ax.set_ylim(-1,10)
ax.set_title('Parabolic Function with Text Notation')
plt.show()