mirror of
https://github.com/Estom/notes.git
synced 2026-04-09 13:58:58 +08:00
matplotlib & pandas
This commit is contained in:
100
Python/matplotlab/gallery/pyplots/text_layout.md
Normal file
100
Python/matplotlab/gallery/pyplots/text_layout.md
Normal file
@@ -0,0 +1,100 @@
|
||||
# 不同文本的布局
|
||||
|
||||
创建具有不同对齐和旋转的文本。
|
||||
|
||||
```python
|
||||
import matplotlib.pyplot as plt
|
||||
import matplotlib.patches as patches
|
||||
|
||||
# build a rectangle in axes coords
|
||||
left, width = .25, .5
|
||||
bottom, height = .25, .5
|
||||
right = left + width
|
||||
top = bottom + height
|
||||
|
||||
fig = plt.figure()
|
||||
ax = fig.add_axes([0,0,1,1])
|
||||
|
||||
# axes coordinates are 0,0 is bottom left and 1,1 is upper right
|
||||
p = patches.Rectangle(
|
||||
(left, bottom), width, height,
|
||||
fill=False, transform=ax.transAxes, 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',
|
||||
fontsize=20, color='red',
|
||||
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)
|
||||
|
||||
ax.set_axis_off()
|
||||
plt.show()
|
||||
```
|
||||
|
||||

|
||||
|
||||
## 参考
|
||||
|
||||
此示例中显示了以下函数,方法,类和模块的使用:
|
||||
|
||||
```python
|
||||
import matplotlib
|
||||
matplotlib.axes.Axes.text
|
||||
matplotlib.pyplot.text
|
||||
```
|
||||
|
||||
## 下载这个示例
|
||||
|
||||
- [下载python源码: text_layout.py](https://matplotlib.org/_downloads/text_layout.py)
|
||||
- [下载Jupyter notebook: text_layout.ipynb](https://matplotlib.org/_downloads/text_layout.ipynb)
|
||||
Reference in New Issue
Block a user