Static Image Export and a New Lead Maintainer
Just two months ago we announced
plotly.py 3.0.0, our biggest release yet. It included first-class Jupyter widget integration, deep validation and typeahead support, and several performance improvements (read more).
Today we’re excited to announce two new developments in the plotly.py library:
Announcement 1. Jon Mease, the open source contributor behind 3.0.0, is stepping up as the lead maintainer of plotly.py. Jon has been working in technical computing and data science for many years. He started working on plotly.py because he wants it all: a library with high quality SVG graphics, GPU acceleration for large datasets, two-way interactivity in Jupyter, standalone dashboard support, and an extensive range of chart types. With Jon at the helm, plotly.py has never been in a better place. Welcome Jon!
Announcement 2. Programmatic static image export is now widely available in plotly.py 3.2.0. Here “programmatic” means the ability to save figures as images from code, without requiring any manual interaction with a web browser (e.g. no save dialog). This has been the most requested feature by the community and seriously broadens the applicability of the library. Thanks to Jon, our community no longer has to choose between interactive graphing and high quality static image exports; with plotly.py you can have it both ways.
Converting a figure to an image is simple and it’s very similar to matplotlib’s
plotly.io.write_image(fig, file, format=None,
scale=None, width=None, height=None)
Figureor a compatible
dict. This is the central declarative object that describes every aspect of a plotly graph.
filemay be a string referring to a local filesystem path, or a file-like object to be written to. If
fileis a string, then the file extension is used to infer the image format if possible.
formatmay be used to explicitly specify the format, and it is required if
fileis not a string with a common extension. Supported formats are png, jpeg (jpg extension supported as well), webp, svg, pdf, and eps (with poppler installed).
heightall work as you would expect.
scale=None, width=None, height=None)
This function may be used to return the binary representation of the image directly (no temp files or messing with
io.BytesIO!). This can be used in conjunction with
IPython.display.Image to display static images directly in the notebook or QtConsole.
The main plotly.py library can be installed either through
pip or through
$ pip install plotly --upgrade
$ conda install -c plotly plotly
$ conda install -c plotly plotly-orca
$ npm install -g firstname.lastname@example.org orca
- Download and install the prebuilt binary
One of the really exciting aspects of our image export functionality is that generating images is really fast. It takes about 2 seconds for the image generating subprocess to start but once it’s started, generating images can be about as fast as
Here are the results of some timing comparisons between plotly.py, matplotlib, bokeh, and altair for saving a 1000 point scatter plot to a PNG and SVG image (get the full notebook here).
Update 09/08/2018: The original version of the chart below showed significantly slower bokeh export times. Thanks to Bryan Van de Ven for pointing out that it is possible to substantially improve the export time by reusing a single selenium webdriver instance across multiple export operations. As far as we know, this approach is not currently available in altair (as of version 2.2.2).
Electron is a cross-platform desktop application technology that is built on top of Chromium, the core of the Chrome browser. With Electron, we wrote and published
orca, a self-contained CLI for rendering static images of plotly graphs. You can either install it with
npm, or you can download our prebuilt binaries for Windows, Mac, and Linux. We create these builds using the CI platforms AppVeyor, Travis, and CircleCI.
Since most plotly.js graphs are rendered in SVG, the resulting images will be publication-quality: The fonts and shapes are crisp, and they’ll stay crisp and unpixelated when you enlarge them in your PowerPoint presentation, or when you’re post-processing in Illustrator.
To create an image,
plotly.py will invoke the
orca command, running it as a background server. Plotly plots are completely described in declarative JSON, so that data is easily transferred from Python to
orca over a local HTTP request, and
orca will draw the graph using
plotly.js and render the image.
orca is run in a subprocess and without a window: it’s completely out of the way. We keep the
orca subprocess running until the main Python process exits so that your code can generate multiple images in a row without waiting for
orca to start each time (
orca takes about 2 seconds to start).
For more on the design, see the original pull request.
plotly.py 3.2.0a try (installation instructions) and let us know how it goes! You can find us on GitHub, Twitter, or our community forum.
- Get started with
plotly.pyin our online documentation, and check out our new tutorials on Static Image Export and Orca Management.
- plotly.py is on GitHub and so is plotly.js and orca. We also have a discourse community forum.
- Follow Jon on twitter and GitHub to keep tabs on where plotly.py is going next.
- All of the work announced here is MIT licensed. We fund our open source development through Plotly Cloud (our online data visualization platform) and through Dash Deployment Server, our PaaS for deploying and managing Dash Apps. Many companies also directly fund our open-source work.
- To stay up to date on plotly’s technical work, follow us on Twitter.
- Interested in our Python products? Check out our 3.0.0 announcement post or our latest project, Dash: a web application framework for Python.