alignment_test.py
来自「非原创。很好的python例子」· Python 代码 · 共 83 行
PY
83 行
#!/usr/bin/env python"""You can precisely layout text in data or axes (0,1) coordinates. Thisexample shows you some of the alignment and rotation specifications tolayout text"""from pylab import *from matplotlib.lines import Line2Dfrom matplotlib.patches import Rectangle# build a rectangle in axes coordsleft, width = .25, .5bottom, height = .25, .5right = left + widthtop = bottom + heightax = gca()p = Rectangle((left, bottom), width, height, fill=False, )p.set_transform(ax.transAxes)p.set_clip_on(False)ax.add_patch(p)ax.text(left, bottom, 'left top', horizontalalignment='left', verticalalignment='top', transform=ax.transAxes)ax.text(left, bottom, 'left bottom', horizontalalignment='left', verticalalignment='bottom', transform=ax.transAxes)ax.text(right, top, 'right bottom', horizontalalignment='right', verticalalignment='bottom', transform=ax.transAxes)ax.text(right, top, 'right top', horizontalalignment='right', verticalalignment='top', transform=ax.transAxes)ax.text(right, bottom, 'center top', horizontalalignment='center', verticalalignment='top', transform=ax.transAxes)ax.text(left, 0.5*(bottom+top), 'right center', horizontalalignment='right', verticalalignment='center', rotation='vertical', transform=ax.transAxes)ax.text(left, 0.5*(bottom+top), 'left center', horizontalalignment='left', verticalalignment='center', rotation='vertical', transform=ax.transAxes)ax.text(0.5*(left+right), 0.5*(bottom+top), 'middle', horizontalalignment='center', verticalalignment='center', transform=ax.transAxes)ax.text(right, 0.5*(bottom+top), 'centered', horizontalalignment='center', verticalalignment='center', rotation='vertical', transform=ax.transAxes)ax.text(left, top, 'rotated\nwith newlines', horizontalalignment='center', verticalalignment='center', rotation=45, transform=ax.transAxes)axis('off')#savefig('alignment_test', dpi=100)show()
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?