我正在尝试将绘图导出为jpg文件。为此,我使用以下代码:
from plotly.offline import iplot, init_notebook_mode
import plotly.graph_objs as go
import plotly.io as pio
import plotly
import os
import numpy as np
init_notebook_mode(connected=True)
N = 100
x = np.random.rand(N)
y = np.random.rand(N)
colors = np.random.rand(N)
sz = np.random.rand(N)*30
fig = go.Figure()
fig.add_scatter(x=x,
y=y,
mode='markers',
marker={'size': sz,
'color': colors,
'opacity': 0.6,
'colorscale': 'Viridis'
});
iplot(fig)
pio.write_image(fig, 'fig1.png')我遇到的问题是ORCA。可以找到这个库,但它已经安装了。这是我得到的错误:
ValueError:需要orca可执行文件才能将图形导出为静态图像,但在'/opt/conda/bin/ orca‘处找到的可执行文件似乎不是有效的绘图orca可执行文件。有关出错原因的详细信息,请参阅此消息的末尾。
如果您还没有安装orca,您可以使用conda进行安装,如下所示:
$ conda install -c plotly plotly-orca或者,请参阅orca项目自述文件中的其他安装方法,网址为https://github.com/plotly/orca。
安装完成后,不再需要进一步的配置。
如果你已经安装了orca,那么由于某种原因,plotly.py无法找到它。在这种情况下,将plotly.io.orca.config.executable属性设置为orca可执行文件的完整路径。例如:
>>> plotly.io.orca.config.executable = '/path/to/orca'更新此可执行文件属性后,请重试导出操作。如果成功,您可能需要保存此配置,以便在以后的会话中自动应用。您可以执行以下操作:
>>> plotly.io.orca.config.save() 如果您仍然有问题,请随时在https://community.plot.ly/c/api/python的论坛上寻求帮助
下面是命令$ /opt/conda/bin/orca --help返回的错误
返回代码: 127 /opt/conda/lib/orca_app/orca:加载共享库时出错: libXtst.so.6:无法打开共享对象文件:没有这样的文件或目录
注意:当在Linux上使用时,orca需要一个X11显示服务器,但没有检测到。请安装X11,或使用Xvfb配置您的系统。有关将orca与Xvfb一起使用的说明,请参阅orca自述文件(https://github.com/plotly/orca)。
有人知道如何修复这个错误吗?
发布于 2020-01-24 16:56:09
为了让Orca在我的Django 2项目中的Ubuntu 18上工作,我不得不投入大量的精力。以下是我所做的最终奏效的方法:
我是在Ubuntu 18.04.3 LTS上做的
下面假设你的用户名是USERNAME,你的虚拟环境目录名为"myvenv“。
的权限
wget https://github.com/plotly/orca/releases/download/v1.2.1/orca-1.2.1-x86_64.AppImage chmod +x orca-1.2.1-x86_64.AppImage
中安装以下软件包
sudo apt-get install desktop-file-utils
sudo apt-get install libgtk2.0-0 sudo apt-get install libgconf-2-4 sudo apt-get install xvfb sudo apt-get install chromium-browser
#!/bin/bash
xvfb-run -a orca-1.2.1-x86_64.AppImage "$@"
发布于 2019-03-27 05:52:48
解决方案在plotly/orca上
这是我所做的,它解决了我的问题:
Download orca-1.2.1-x86_64.AppImage
ln -s orca-1.2.1-x86_64.AppImage orca,然后您会看到一个文件,并将其命名为orca-executable.sh,其内容为#!/bin/bash
xvfb-运行-a orca "$@"
然后将以下代码行添加到脚本中
plotly.io.orca.config.executable = '/path/to/orca/orca-executable.sh'路径/path/to/orca下的文件:
rwxrwxrwx 1 root root 26 Feb 14 03:09 orca -> orca-1.2.1-x86_64.AppImage*
-rwxr-xr-x 1 root root 51607939 Feb 14 03:08 orca-1.2.1-x86_64.AppImage*
-rwxr-xr-x 1 root root 34 Feb 14 03:33 orca-executable.sh*发布于 2019-12-24 06:31:16
在Windows上对我起作用的是:
- Download windows-release.zip from [https://github.com/plotly/orca/releases](https://github.com/plotly/orca/releases)
- Install the executable
- Right click on the desktop newly created Orca icon to get the path where the application was installed (in my case `C:\Users\ventafri\AppData\Local\Programs\orca\orca.exe`).
- From the plotly\io folder (in my case `C:\Users\ventafri\AppData\Local\Programs\Python\Python36\Lib\site-packages\plotly\io`) open `_orca.py`
替换:
# Try to find an executable
# -------------------------
# Search for executable name or path in config.executable
executable = which(config.executable)
path = os.environ.get("PATH", os.defpath)
formatted_path = path.replace(os.pathsep, "\n ")通过以下方式:
# Try to find an executable
# -------------------------
# Search for executable name or path in config.executable
executable = r"C:\Users\ventafri\AppData\Local\Programs\orca\orca.exe"
path = os.environ.get("PATH", os.defpath)
formatted_path = path.replace(os.pathsep, "\n ")https://stackoverflow.com/questions/53710227
复制相似问题