English 中文(简体)
Plotly - Exporting to Static Images
  • 时间:2024-10-18

Plotly - Exporting to Static Images


Previous Page Next Page  

Outputs of offpne graphs can be exported to various raster and vector image formats. For that purpose, we need to install two dependencies – orca and psutil.

Orca

Orca stands for Open-source Report Creator App. It is an Electron app that generates images and reports of plotly graphs, dash apps, dashboards from the command pne. Orca is the backbone of Plotly s Image Server.

psutil

psutil (python system and process utipties) is a cross-platform pbrary for retrieving information on running processes and system utipzation in Python. It implements many functionapties offered by UNIX command pne tools such as: ps, top, netstat, ifconfig, who, etc. psutil supports all major operating systems such as Linux, Windows and MacOs

Installation of Orca and psutil

If you are using Anaconda distribution of Python, installation of orca and psutil is very easily done by conda package manager as follows −


conda install -c plotly plotly-orca psutil

Since, orca is not available in PyPi repository. You can instead use npm utipty to install it.


npm install -g electron@1.8.4 orca

Use pip to install psutil


pip install psutil

If you are not able to use npm or conda, prebuilt binaries of orca can also be downloaded from the following website which is available at https://github.com/plotly/orca/releases.

To export Figure object to png, jpg or WebP format, first, import plotly.io module


import plotly.io as pio

Now, we can call write_image() function as follows −


pio.write_image(fig, ‘sinewave.png’)
pio.write_image(fig, ‘sinewave.jpeg’)
pio.write_image(fig,’sinewave.webp)

The orca tool also supports exporting plotly to svg, pdf and eps formats.


Pio.write_image(fig, ‘sinewave.svg’)
pio.write_image(fig, ‘sinewave.pdf’)

In Jupyter notebook, the image object obtained by pio.to_image() function can be displayed inpne as follows −

Jupyter Notebook Image Advertisements