mirror of
https://github.com/Estom/notes.git
synced 2026-02-03 18:44:19 +08:00
29 lines
827 B
Markdown
29 lines
827 B
Markdown
# 多光标
|
|
|
|
同时在多个图上显示光标。
|
|
|
|
此示例生成两个子图,并将光标悬停在一个子图中的数据上,该数据点的值分别显示在两个子图中。
|
|
|
|

|
|
|
|
```python
|
|
import numpy as np
|
|
import matplotlib.pyplot as plt
|
|
from matplotlib.widgets import MultiCursor
|
|
|
|
t = np.arange(0.0, 2.0, 0.01)
|
|
s1 = np.sin(2*np.pi*t)
|
|
s2 = np.sin(4*np.pi*t)
|
|
|
|
fig, (ax1, ax2) = plt.subplots(2, sharex=True)
|
|
ax1.plot(t, s1)
|
|
ax2.plot(t, s2)
|
|
|
|
multi = MultiCursor(fig.canvas, (ax1, ax2), color='r', lw=1)
|
|
plt.show()
|
|
```
|
|
|
|
## 下载这个示例
|
|
|
|
- [下载python源码: multicursor.py](https://matplotlib.org/_downloads/multicursor.py)
|
|
- [下载Jupyter notebook: multicursor.ipynb](https://matplotlib.org/_downloads/multicursor.ipynb) |