我以前没有使用过plotly,一直在尝试将示例图像代码导出为png格式。我已经安装了plotly和kaleido,并在Python 3上运行了代码,但是没有任何反应。
#Here is the code:
import plotly.express as px
import numpy as np
# RGB Data as numpy array
img_rgb = np.array([[[255, 0, 0], [0, 255, 0], [0, 0, 255]],], dtype=np.uint8)
fig = px.imshow(img_rgb)
fig.show()
fig.write_image("fig.png")
根据Plotly文档,这应该可以解决问题,但是我无法获得PNG图像。没有显示错误,没有警告......就像Python陷入了无限循环一样。我甚至无法停止终端运行。
我使用的是Python 3.9.6 64位版本。 我尝试过最新版的Plotly(5.3.1)和旧版(4.14.3),但是我遇到了同样的问题。 python -m pip install plotly
Kaleido是最新版(0.2.1),但我也尝试过版本(0.2.0)。 python -m pip install -U kaleido
我可能做错了什么?
更新:我在另一台电脑上尝试了相同的过程,并且它可以正常工作。任何想法为什么第一台电脑无法运行代码?
fig.show(renderer='png')
或fig.show(renderer='svg')
也会发生同样的情况。如果我中断内核,跟踪显示它卡在base.py的第192行:startup_response_string = self._proc.stdout.readline().decode('utf-8')
。 - the.real.gruycho