mirror of
https://github.com/Estom/notes.git
synced 2026-04-10 14:28:00 +08:00
matplotlib & pandas
This commit is contained in:
42
Python/matplotlab/gallery/userdemo/annotate_text_arrow.md
Normal file
42
Python/matplotlab/gallery/userdemo/annotate_text_arrow.md
Normal file
@@ -0,0 +1,42 @@
|
||||
# 注释文本箭头
|
||||
|
||||
```python
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
fig, ax = plt.subplots(figsize=(5, 5))
|
||||
ax.set_aspect(1)
|
||||
|
||||
x1 = -1 + np.random.randn(100)
|
||||
y1 = -1 + np.random.randn(100)
|
||||
x2 = 1. + np.random.randn(100)
|
||||
y2 = 1. + np.random.randn(100)
|
||||
|
||||
ax.scatter(x1, y1, color="r")
|
||||
ax.scatter(x2, y2, color="g")
|
||||
|
||||
bbox_props = dict(boxstyle="round", fc="w", ec="0.5", alpha=0.9)
|
||||
ax.text(-2, -2, "Sample A", ha="center", va="center", size=20,
|
||||
bbox=bbox_props)
|
||||
ax.text(2, 2, "Sample B", ha="center", va="center", size=20,
|
||||
bbox=bbox_props)
|
||||
|
||||
|
||||
bbox_props = dict(boxstyle="rarrow", fc=(0.8, 0.9, 0.9), ec="b", lw=2)
|
||||
t = ax.text(0, 0, "Direction", ha="center", va="center", rotation=45,
|
||||
size=15,
|
||||
bbox=bbox_props)
|
||||
|
||||
bb = t.get_bbox_patch()
|
||||
bb.set_boxstyle("rarrow", pad=0.6)
|
||||
|
||||
ax.set_xlim(-4, 4)
|
||||
ax.set_ylim(-4, 4)
|
||||
|
||||
plt.show()
|
||||
```
|
||||
|
||||
## 下载这个示例
|
||||
|
||||
- [下载python源码: annotate_text_arrow.py](https://matplotlib.org/_downloads/annotate_text_arrow.py)
|
||||
- [下载Jupyter notebook: annotate_text_arrow.ipynb](https://matplotlib.org/_downloads/annotate_text_arrow.ipynb)
|
||||
Reference in New Issue
Block a user