-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
DOC: improve annotation demo #6455
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
'axes pixels' : pixels from lower left corner of axes | ||
'axes fraction' : 0,0 is lower left of axes and 1,1 is upper right | ||
'offset points' : Specify an offset (in points) from the xy value | ||
'offset pixels' : Specify an offset (in pixels) from the xy value | ||
'data' : use the axes data coordinate system | ||
|
||
Optionally, you can specify arrow properties which draws and arrow | ||
|
@@ -29,9 +30,7 @@ | |
any key for matplotlib.patches.polygon (e.g., facecolor) | ||
|
||
For physical coordinate systems (points or pixels) the origin is the | ||
(bottom, left) of the figure or axes. If the value is negative, | ||
however, the origin is from the (right, top) of the figure or axes, | ||
analogous to negative indexing of sequences. | ||
(bottom, left) of the figure or axes. | ||
""" | ||
|
||
|
||
|
@@ -50,37 +49,39 @@ | |
s = np.cos(2*np.pi*t) | ||
line, = ax.plot(t, s, lw=3, color='purple') | ||
|
||
ax.annotate('axes center', xy=(.5, .5), xycoords='axes fraction', | ||
horizontalalignment='center', verticalalignment='center') | ||
ax.annotate('figure pixels', | ||
xy=(10, 10), xycoords='figure pixels') | ||
|
||
ax.annotate('pixels', xy=(20, 20), xycoords='figure pixels') | ||
ax.annotate('figure points', xy=(80, 80), | ||
xycoords='figure points') | ||
|
||
ax.annotate('points', xy=(100, 300), xycoords='figure points') | ||
|
||
ax.annotate('offset', xy=(1, 1), xycoords='data', | ||
xytext=(-15, 10), textcoords='offset points', | ||
ax.annotate('point offset from data', xy=(2, 1), | ||
xycoords='data', | ||
xytext=(-15, 25), textcoords='offset points', | ||
arrowprops=dict(facecolor='black', shrink=0.05), | ||
horizontalalignment='right', verticalalignment='bottom', | ||
) | ||
|
||
ax.annotate('local max', xy=(3, 1), xycoords='data', | ||
ax.annotate('axes fraction', xy=(3, 1), xycoords='data', | ||
xytext=(0.8, 0.95), textcoords='axes fraction', | ||
arrowprops=dict(facecolor='black', shrink=0.05), | ||
horizontalalignment='right', verticalalignment='top', | ||
) | ||
|
||
ax.annotate('a fractional title', xy=(.025, .975), | ||
ax.annotate('figure fraction', xy=(.025, .975), | ||
xycoords='figure fraction', | ||
horizontalalignment='left', verticalalignment='top', | ||
fontsize=20) | ||
|
||
# use negative points or pixels to specify from right, top -10, 10 | ||
# is 10 points to the left of the right side of the axes and 10 | ||
# points above the bottom | ||
ax.annotate('bottom right (points)', xy=(-10, 10), | ||
xycoords='axes points', | ||
horizontalalignment='right', verticalalignment='bottom', | ||
fontsize=20) | ||
ax.annotate('pixel offset from axes fraction', xy=(1, 0), | ||
xycoords='axes fraction', | ||
xytext=(-20, 20), | ||
textcoords='offset pixels', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. None of the documentation, including the block at the top of the example, lists "offset pixels" as a valid option. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed here and removed the comments about negative directions. On my to-do list for today is a more general going over of the annotation docs as I think we cleaned up the arrow handling we may have broken API a bit (using xytext without arrowprops does not draw an arrow any more). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, did we remove all negative direction handling? |
||
horizontalalignment='right', | ||
verticalalignment='bottom') | ||
|
||
|
||
if 1: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because we removed the special casing of negative numbers on the
axes *
coordinate systems (see #4843)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(continued) that example will put text that is right algined starting at 20px to the left of left edge of the axes. The example in the PR puts the text 20px to the left of the right edge of the axes.