gpt4 book ai didi

Python - matplotlib 极坐标图问题 - "posx and posy should be finite values"

转载 作者:行者123 更新时间:2023-11-28 19:02:09 33 4
gpt4 key购买 nike

切换到新系统后,我遇到了 matplotlib 的奇怪错误。我正在尝试创建一个 r 轴反转的极坐标图。因此,在我的情况下,从 90 运行到 0。这在我以前的系统上运行良好,具有最小的工作示例:

import matplotlib.pyplot as plt
from random import randint

fig, ax = plt.subplots(subplot_kw=dict(projection='polar'))
plt.scatter([randint(0, 360)], [randint(0, 90)])
ax.set_rlim(90, 0)
ax.set_theta_zero_location('N')
ax.set_theta_direction('clockwise')

plt.show()

在我的新系统上运行产量

posx and posy should be finite values
posx and posy should be finite values
/usr/local/lib/python3.5/dist-packages/numpy/core/fromnumeric.py:83: RuntimeWarning: invalid value encountered in reduce
return ufunc.reduce(obj, axis, dtype, out, **passkwargs)
posx and posy should be finite values
posx and posy should be finite values
posx and posy should be finite values

到目前为止,我发现错误是由包含 ax.set_rlim(90, 0) 的行中的反转 r 轴触发的(使用 ax.set_rlim(0, 90) 工作正常)。

我的系统设置是

  • Debian 4.9.110-1 (2018-07-05) x86_64 GNU/Linux
  • python 3.5.3
  • Matplotlib 2.2.2

旧系统非常相似,我无法恢复使用过的版本。这是新版本中的一些已知错误吗?我找不到与极坐标图有关的与此错误消息相关的任何信息。

最佳答案

我现在通过将标签更改为从 90 到 0 的范围来做一个相当草率的解决方法

ticklabels = ax.get_yticklabels()
labels = range(80, 0, -10)
for i in range(0, len(labels)):
ticklabels[i] = str(labels[i])
ax.set_yticklabels(ticklabels)

所有半径值也必须相应调整。在这种情况下,90 - r_value 才能正确显示。

关于Python - matplotlib 极坐标图问题 - "posx and posy should be finite values",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51610595/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com