Google Colab:运行 Fig.write_image() 时出现问题

Jua*_*zco 7 python conda plotly google-colaboratory

我正在尝试使用以下代码保存绘图线静态图像:

import plotly 
import plotly.express as px
fig = px.line(EFBCg_f[1:12], x='time(ms)', y="C(n)", width=800, height=200)
fig.show()
file='Results/filename.png'
fig.write_image(file)
Run Code Online (Sandbox Code Playgroud)

在网站https://plotly.com/python/static-image-export/中,标记为安装以下任一者的请求:

!pip install -U kaleido
Run Code Online (Sandbox Code Playgroud)

或者

conda install -c plotly python-kaleido
Run Code Online (Sandbox Code Playgroud)

我使用 pip 安装 kaleido 没有问题,但创建了一个空文件。

因此,我尝试使用 coda 安装 kaleido,但首先我必须安装 coda,因为它不是 Google Colab 原生的。我按如下方式进行:

!pip 安装 conda

我没有问题。然后,我运行命令:

!conda install -c plotly python-kaleido
Run Code Online (Sandbox Code Playgroud)

我有下一个回复:

ERROR: The install method you used for conda--probably either `pip install conda`
or `easy_install conda`--is not compatible with using conda as an application.
If your intention is to install conda as a standalone application, currently
supported install methods include the Anaconda installer and the miniconda
installer.  You can download the miniconda installer from
https://conda.io/miniconda.html.
Run Code Online (Sandbox Code Playgroud)

现在,我卡住了。

如果您能帮助找到问题,我将不胜感激。谢谢。胡安.

小智 5

要在 Google Colab 中先保存图像,请运行:

!pip install -U kaleido
Run Code Online (Sandbox Code Playgroud)

然后转到Runtime > Restart Runtime菜单中。

重新启动运行时后,重新运行您的代码。(您不需要重新运行 pip 命令)。

请参阅此讨论,了解为什么有时需要重新启动运行时才能在 Google Colab 中安装软件包。


小智 0

试试这个(tnx 给 Greg Hogg https://youtu.be/qNF1HqBvpGE

!wget https://github.com/plotly/orca/releases/download/v1.2.1/orca-1.2.1-x86_64.AppImage -O /usr/local/bin/orca

!chmod +x /usr/local/bin/orca

!apt-get install xvfb libgtk2.0-0 libgconf-2-4
Run Code Online (Sandbox Code Playgroud)