Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 43346e1

Browse filesBrowse files
committed
Merge pull request #6455 from tacaswell/doc_annotation
DOC: improve annotation demo
2 parents 5bad764 + 37eb2aa commit 43346e1
Copy full SHA for 43346e1

File tree

Expand file treeCollapse file tree

1 file changed

+17
-16
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+17
-16
lines changed

‎examples/pylab_examples/annotation_demo.py

Copy file name to clipboardExpand all lines: examples/pylab_examples/annotation_demo.py
+17-16Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
'axes pixels' : pixels from lower left corner of axes
1414
'axes fraction' : 0,0 is lower left of axes and 1,1 is upper right
1515
'offset points' : Specify an offset (in points) from the xy value
16+
'offset pixels' : Specify an offset (in pixels) from the xy value
1617
'data' : use the axes data coordinate system
1718
1819
Optionally, you can specify arrow properties which draws and arrow
@@ -29,9 +30,7 @@
2930
any key for matplotlib.patches.polygon (e.g., facecolor)
3031
3132
For physical coordinate systems (points or pixels) the origin is the
32-
(bottom, left) of the figure or axes. If the value is negative,
33-
however, the origin is from the (right, top) of the figure or axes,
34-
analogous to negative indexing of sequences.
33+
(bottom, left) of the figure or axes.
3534
"""
3635

3736

@@ -50,37 +49,39 @@
5049
s = np.cos(2*np.pi*t)
5150
line, = ax.plot(t, s, lw=3, color='purple')
5251

53-
ax.annotate('axes center', xy=(.5, .5), xycoords='axes fraction',
54-
horizontalalignment='center', verticalalignment='center')
52+
ax.annotate('figure pixels',
53+
xy=(10, 10), xycoords='figure pixels')
5554

56-
ax.annotate('pixels', xy=(20, 20), xycoords='figure pixels')
55+
ax.annotate('figure points', xy=(80, 80),
56+
xycoords='figure points')
5757

58-
ax.annotate('points', xy=(100, 300), xycoords='figure points')
59-
60-
ax.annotate('offset', xy=(1, 1), xycoords='data',
61-
xytext=(-15, 10), textcoords='offset points',
58+
ax.annotate('point offset from data', xy=(2, 1),
59+
xycoords='data',
60+
xytext=(-15, 25), textcoords='offset points',
6261
arrowprops=dict(facecolor='black', shrink=0.05),
6362
horizontalalignment='right', verticalalignment='bottom',
6463
)
6564

66-
ax.annotate('local max', xy=(3, 1), xycoords='data',
65+
ax.annotate('axes fraction', xy=(3, 1), xycoords='data',
6766
xytext=(0.8, 0.95), textcoords='axes fraction',
6867
arrowprops=dict(facecolor='black', shrink=0.05),
6968
horizontalalignment='right', verticalalignment='top',
7069
)
7170

72-
ax.annotate('a fractional title', xy=(.025, .975),
71+
ax.annotate('figure fraction', xy=(.025, .975),
7372
xycoords='figure fraction',
7473
horizontalalignment='left', verticalalignment='top',
7574
fontsize=20)
7675

7776
# use negative points or pixels to specify from right, top -10, 10
7877
# is 10 points to the left of the right side of the axes and 10
7978
# points above the bottom
80-
ax.annotate('bottom right (points)', xy=(-10, 10),
81-
xycoords='axes points',
82-
horizontalalignment='right', verticalalignment='bottom',
83-
fontsize=20)
79+
ax.annotate('pixel offset from axes fraction', xy=(1, 0),
80+
xycoords='axes fraction',
81+
xytext=(-20, 20),
82+
textcoords='offset pixels',
83+
horizontalalignment='right',
84+
verticalalignment='bottom')
8485

8586

8687
if 1:

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.