Plotly-express-18-plotly输出静态图
本文介绍的是如何在Plotly
中输出静态图,尝试使用了两种方式:
- Kaleido
- Orca
输出的时候可以指定不同的格式:png\jpeg\pdf
等
Orca
Orca is a pipeline orchestration tool that allows you to define dynamic data sources and explicitly connect them to processing functions. Orca has many features for working with Pandas data structures, but it can be used with anything.
Orca has explit goals of flexibility, transparency, lazy execution, and encouraging good practices. Those goals are achieved by:
-
Flexibility
- Users may write and run any Python
-
Transparency
- Dependencies between data and processing units are explicitly listed
- Your code is a record of everything that happens
-
Lazy execution
- Orca only calls functions if they are explicitly needed
-
Good practices
- Encourage small, functional units
- Encourage code re-use
代码
1 | import plotly.graph_objects as go |
图片
报错
但是当在使用Orca进行保存的时候出现了报错:
1 | import os |
出现的报错:原因在于orca没有添加到环境变量中
1 | ValueError Traceback (most recent call last) |
解决
- 先检查Orca是否安装
With the dependencies installed, install Orca with pip:
1 | pip install orca |
Orca may also be installed with conda:
1 | conda install -c udst orca |
Add the server option to include the optional server dependencies:
1 | pip install orca[server] |
- 如果安装之后,将Orca添加到电脑的环境变量中即可,具体参考Mac/Linux环境变量设置
- 其他依赖
Orca的使用和安装挺麻烦的,那么Kaleido来了😃
Kaleido
Intro
Kaleido is a cross-platform library for generating static images (e.g. png, svg, pdf, etc.) for web-based visualization libraries, with a particular focus on eliminating external dependencies.
The project’s initial focus is on the export of plotly.js images from Python for use by plotly.py, but it is designed to be relatively straight-forward to extend to other web-based visualization libraries, and other programming languages.
The primary focus of Kaleido (at least initially) is to serve as a dependency of web-based visualization libraries like plotly.py. As such, the focus is on providing a programmatic-friendly, rather than user-friendly, API.
https://www.ctolib.com/plotly-Kaleido.html
install
安装直接pip install kaleido
Install the kaleido wheel.
1 | $ pip install kaleido |
Install plotly as well
1 | $ pip install plotly |
demo
1 | from kaleido.scopes.plotly import PlotlyScope |
相比较于Orca,Kaleido还是非常简洁的