1

根据 mpldatacursor 0.7.1项目描述,它说“mpldatacursor 为 matplotlib 提供交互式“数据光标”(可点击的注释框)。

我使用项目描述中的代码,但我只是得到图像。当我单击图像时,它不显示注释框。

我的 Python 版本是 3.8,Pycharm 版本是专业版 2019.2。顺便说一句,我运行代码时没有错误。

有谁知道为什么?

import matplotlib.pyplot as plt
import numpy as np
from mpldatacursor import datacursor

data = np.arange(100).reshape((10,10))

fig, axes = plt.subplots(ncols=2)
axes[0].imshow(data, interpolation='nearest', origin='lower')
axes[1].imshow(data, interpolation='nearest', origin='upper',
                     extent=[200, 300, 400, 500])
datacursor(display='single')

fig.suptitle('Click anywhere on the image')

plt.show()

在此处输入图像描述

4

1 回答 1

0

他们已经更新了代码,现在可以使用了。

他们将其删除from mpldatacursor import datacursor并替换为import mplcursors. 您可能需要安装mplcursors

更新后的代码如下:

import matplotlib.pyplot as plt
import numpy as np
import mplcursors

data = np.arange(100).reshape((10, 10))

fig, axes = plt.subplots(ncols=2)
axes[0].imshow(data, interpolation="nearest", origin="lower")
axes[1].imshow(data, interpolation="nearest", origin="upper",
                 extent=[200, 300, 400, 500])
mplcursors.cursor()

fig.suptitle("Click anywhere on the image")

plt.show()
于 2020-11-09T15:57:49.223 回答