python - Matplotlib 意外 contains_point() 导致嵌套圆环图
问题描述
我在尝试让Patch.contains_point()
方法在嵌套圆环图中工作时遇到问题。这是我的代码:
fig, ax = plt.subplots()
ax.axis('equal')
width = 0.3
pie, _ = ax.pie([120, 120], radius=1)
plt.setp(pie, width=width, edgecolor='white')
pie2, _ = ax.pie([60, 60, 37, 40, 29, 10], radius=1 - width)
plt.setp(pie2, width=width, edgecolor='white')
def button_release(event):
if event.inaxes == ax:
pos = [event.x, event.y]
for i, p in enumerate([pie, pie2]):
for j, w in enumerate(p):
if w.contains_point(pos):
print(i, j)
fig.canvas.mpl_connect("button_release_event", button_release)
plt.show()
结果是这个图表:
打印的“坐标”完全符合预期,直到外环只包含一个值,图表如下所示:
在这种情况下,单击任何楔形总是会在外圈上产生积极的结果。所以当我点击外圈时,我得到了(0, 0)
,没关系。但是当我点击内圈的第一个楔子时,我得到了(0, 0)
and (1, 0)
。与内圈上的其他楔块相同。
我还注意到,在这种情况下,单击图表内的空圆圈会导致误报(0, 0)
,而在第一个图表上并非如此。
这contains_point()
是假设的工作方式吗?
解决方案
推荐阅读
- r - 如何从数据框列表中删除列?
- python - 如何将 MyPy 将接受的类型提示作为参数传递给在内部定义函数的函数?
- c# - Android设备管理器系统镜像下载错误,Xamarin
- configuration - 我可以设置截止时间吗
- terraform - Is there any way to reference to old plan in terraform?
- javascript - Cypress:如何检查我的请求负载数据?
- r - 用一个函数生成不同的类向量
- javascript - 确保文件遵循样式指南
- java - JScrollPane 中 JTextPane 文本后面的静态图像
- javascript - 用数组 javascript 过滤掉数组