我正在尝试执行以下代码:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib
%matplotlib inline
import seaborn as sns
import plotly.graph_objects as go
from plotly.offline import init_notebook_mode, iplot
init_notebook_mode(connected=True)
from sklearn.preprocessing import QuantileTransformer
import os
if not os.path.exists("images"):
os.mkdir("images")
# import orca
import plotly.io as pio
pio.orca.config.executable = '/path/to/orca'
pio.orca.ensure_server()
import psutil
我得到的:
ValueError Traceback (most recent call last)
<ipython-input-89-6e2b31e44303> in <module>
25 import plotly.io as pio
26 pio.orca.config.executable = '/path/to/orca'
---> 27 pio.orca.ensure_server()
28
29 import psutil
~/Library/Python/3.7/lib/python/site-packages/plotly/io/_orca.py in ensure_server()
1368 Install using conda:
1369 $ conda install psutil
-> 1370 """
1371 )
1372
ValueError: Image generation requires the psutil package.
Install using pip:
$ pip install psutil
Install using conda:
$ conda install psutil
该软件包已安装,为了以防万一,我也重新安装了该软件包,但仍然收到错误消息。
最终目标是能够使用fig.write_image("images/fig1.png")
答案 0 :(得分:0)
如果要将绘图图形保存为图像。
对我有用的是安装kaleido
然后使用万花筒引擎
例如
pip 安装 Kaleido plotly.io.write_image(fig, 'fig1.jpeg', format='jpeg',validate=False, engine='kaleido')
也请参阅以下问题/答案: How to save plotly express plot into a html or static image file?