Published in


🌟 Introducing 3.0.0 🌟

TLDR; You can download and install 3.0.0 today with pip install plotly (or pip install plotly --upgrade if you’ve installed the Plotly Python library in the past).

Last October, at our New York City Dash Workshops, an attendee showed us something really special. Jon Mease (@jonmmease), a data scientist and software developer from the Johns Hopkins Applied Physics Laboratory, had spent three months working on a fork of, our open source Python graphing library:

I’ve spent years working in scientific and engineering domains and I’m really excited about the benefits of bringing the best of the Python open data science ecosystem to these areas.

Data visualization is a critical component of analysis in these domains, and even though there are literally dozens of libraries in Python’s Visualization Landscape, I couldn’t find one that supported the full set of features that I need (or at least that I want 😃). These include: Support for a wide range of plot types covering statistical, 3D, and geographic use cases; efficient GPU acceleration to handle realistically large data sets; offline export of high-quality static images; two-way interactivity in the Jupyter Notebook; and stand-alone dashboarding support.

So I decided to start with the technology that I felt was the closest (plotly.js with and Dash), and try my hand at filling in some of the gaps. As you’ll see in this post, I got a bit carried away 😌

— Jon

So Jon dug deep into plotly.js and started creating his own Pythonic interface to the library. It started with typeahead support and grew and grew to include first class Jupyter widgets, fast typed arrays, deep figure validation, offline static image export, and more. Now, one year after his first commit and nine months after our workshops, we’ve integrated Jon’s fork into the official library and are excited to announce our biggest release yet: 3.0.0 🎉

Eager to get started? Download and install 3.0.0 today with pip install plotly (or pip install plotly --upgrade if you’ve installed the Plotly Python library in the past).

First Class Jupyter Widget Support

3.0.0 introduces a new Jupyter widget class: plotly.graph_objs.FigureWidget

FigureWidget has the same call signature as our existing Figure, and it’s made specifically for Jupyter Notebook and JupyterLab environments.

Print the widget, see the figure. Just like every other object in Jupyter. plotly.offline.init_notebook_mode and plotly.offline.iplot are no longer necessary.

This figure widget is synced up with the plotly.js JavaScript figure object, so you can access all of the properties of the figure, including the dynamic default properties that were previously only available in the JavaScript context.

Introspect all of the default properties of the plotly figure. Thanks to the Jupyter widget framework, these properties are accessed directly from the JavaScript context.

This widget is compatible with the rest of the widget framework and has event listeners for hovering, clicking, and selecting points and zooming into regions.

Tying together the Plotly FigureWidget with the Text IPywidget to display Walmart Store openings over time.
Tying together Plotly and Datashader with the new FigureWidget’s “property change” callbacks. Whenever the axes ranges change, the callback gets fired, recomputing the server-rendered image with Datashader. View the source.

An Imperative Alternative

plotly.js graphs are declarative. This means that every aspect of the charts (the colors of the bars, the axes grid lines, the position of annotations) are completely described through a set of attributes. This set of attributes is the “Plotly JSON Chart Schema,” and it describes every aspect of over 33 chart types (and counting)!

Our interface to this library has always been declarative. You describe what the graph should look like, not how to draw it.

plotly 3.0.0 introduces a set of imperative methods for manipulating and exploring the figure in Jupyter’s interactive computing environments. It’s easier than ever to traverse the figure structure and manipulate the graph. The imperative methods are one-to-one with the declarative attributes, so it’s easy to switch between describing your graph entirely upfront (declarative method) and editing it on-the-fly in Jupyter (imperative method).

Interactively editing the attributes of a rendered Plotly `GraphWidget` in Jupyter Notebook.

Tab-Complete Support

With, it’s easier than ever to discover the attributes of your graphs without leaving the notebook. generates rich Python classes from the chart schema with great docstrings and perfect tab-complete support.

For any instantiated figure, you can traverse through all attributes of the figure and view their full descriptions:

Tab complete all the way down.

And the docstrings are beautiful. They’re pulled directly from the plotly.js schema so when plotly.js updates the underlying source code, will automatically get the new doc strings.

All of the traces are accessible under the `add_*` methods of a figure. In Jupyter, type shift+tab to pull up the inline-documentation and shift+tab a second time to expand it.

Typeahead also works for the plotly.graph_objs, the pythonic wrappers around each of the chart types and groups of nested attributes.

Declarative graph objects with input argument tab complete, all the way down!

Calling help on these objects displays rich descriptions, all of the available keyword arguments, and descriptions of each argument. Complete and explicit.

These nice tab-complete docstrings also work with traditional code editors like PyCharm:

Deep typeahead attribute documentation across all plotly graph properties in PyCharm.

I’ve been spoiled over the years by the level of auto-completion and inline documentation that powerful IDEs like IntelliJ and Visual Studio provide for statically typed languages like Java and C#. My goal was to recreate this experience when working with the object hierarchy. After several iterations on the design of the generated classes and their associated docstrings, I think I’ve gotten pretty close.

Code generation can be a lot of fun when you have a clearly defined schema!

— Jon

Deep Validation and Helpful Error Messages

The plotly.js chart schema provides strict types for each attribute. There are 14 data types and now provides strict type validators and type-specific exceptions for each of them.

The validators are strict and helpful. For example, they’ll raise errors if your strings aren’t valid CSS color strings:

Or if a number is outside of the valid range:

Or if the string isn’t one of the enumerated values:

Performance Improvements

Plotting large data interactively is now faster than ever:

  • figure specifications are now serialized and transferred to plotly.js using the Widget Message Protocol over the Jupyter Comms infrastructure.
  • Thanks to the great work of the ipywidgets team, Python numpy arrays are now transferred into JavaScript TypedArrays without any intermediate UTF-8 encoding. We’d especially like to thank Maarten Breddels, Sylvain Corlay, and Jason Grout for laying very thoughtful foundations for this. We’re standing on the shoulders of giants!
  • plotly.js provides direct support for TypedArrays (added in v0.35.0) and it provides a super fast WebGL pathway for many trace types.

Plotting 1M points in Jupyter used to take 35 seconds. Now it takes only three. And the result is a responsive, completely interactive chart. 🚀

Plotting an interactive chart with 1M data points in 1… 2… 3! seconds 🐎
Fast client-side interactivity with 1M scatter points thanks to plotly.js’s WebGL renderer.

I’ve worked with a lot of data visualization libraries over the years, both proprietary and open source, and I don’t know of any that can both display a million points this quickly, and support zooming, panning, and selection at interactive speed.

(And now that I’ve I said this, I look forward to learning about some in the Hacker News discussion of this post 😉)

— Jon

Context Manager for Animations

Two years ago, we introduced an animation interface in plotly.js. Previously, it’s been possible to create animations in by defining a set of transitions up-front (frames). Now, in 3.0.0, you can define the animation transitions on-the-fly with a new ContextManager.

For example, here’s how to animate smooth transitions of a line chart with ipywidgets.IntSlider.

Using the animation context manager to provide smooth transitions of updates in plotly.js. animations use plotly.js’s underlying Plotly.animate method.

JupyterLab Support 3.0.0’s FigureWidget is completely compatible with the new JupyterLab environment.

Interactive coding in the new JupyterLab environment with the FigureWidget. The FigureWidget is within an output cell of a notebook, pulled out as a separate view in the pane on the right. The `fig.add_histogram2dcontour` method is one of the new imperative API interfaces, designed specifically for the interactive Jupyter computing environments.

Static Image Export

plotly.js graphs are rendered with JavaScript in a browser context. In order to create static images of these charts, without opening a browser, we needed a way to render the graphs in some type of headless browser.

In May, we open-sourced Orca, a command-line application that generates static images of plotly graphs. Orca has been used in production at Plotly for about nine months, creating images for tens of millions of charts.

Orca is the technology for creating static images of Plotly graphs. We’re working on bundling Orca as an optional dependency in the official package. For now, follow the instructions in the Orca repository.

Backwards Compatibility

At Plotly, we take backwards compatibility pretty seriously.

Over the last five years of developing plotly.js, we’ve published over 100 releases, all without a single breaking change to the API. graphs are rendered with plotly.js, so this release does not change the way that your graphs are rendered. The attributes of the graphs remain one-to-one with plotly.js, so the declarative interface to the figures (data, layout, and all of the nested properties within) has not changed either.

What has changed is the structure of the Python classes that wrap these attributes: plotly.graph_objs (“go”). We’re now placing our nested properties, like go.Marker, in a namespace underneath their parent attribute. That is, go.Marker is now accessible as go.scatter.Marker or or whatever trace it is nested within. By providing unique objects under the parent-trace namespace, we can provide better validation (the properties for a marker object within a scatter trace may be different than the properties of a marker object within a bar trace). Although deprecated, the previous objects are still supported, they just won’t provide the same level of validation as our new objects.

Of course, you’re not required to use these higher level objects. You can still write your graphs as straight dictionaries and lists. Or, you can mix-and-match. Here are four equivalent representations of a trace:

We have a more detailed document in our plotly 3.0.0 migration guide. Please let us know if we’ve missed anything in a GitHub issue!

Looking Forward and Further Resources

  • 3.0.0 is a major release which means there are some breaking changes. Get ahead of the release by trying out our release candidate with our migration guide. Questions, issues? Please make an issue 🙇
  • Jon will be speaking about v3.0.0 at SciPy 2018 in Austin. If you’re there, come say hello! 👋
  • Jon also wrote a paper for SciPy 2018 outlining these features and, more technically, the underlying architecture of the code. Check out the SciPy abstract online.
  • Can’t make it to SciPy? Jon will be giving a webinar about 3.0.0 on July 25. Sign up here.
  • Dash, our open source Python library for standalone analytic apps, uses and is compatible with v3.0.0.
  • The underlying graphing library that powers (and other libraries like Dash) is plotly.js. This library is in active development. View our latest releases on GitHub.
  • More of an R person? Carson has been making a lot of fantastic improvements in the Plotly R library lately.
  • Follow our latest work with Twitter: @plotlygraphs
  • Much of our open source work is funded directly from organizations that have budgets for software. Many thanks to everyone that has supported us so far ❤️. Interested in sponsoring a particular feature? Please get in touch.
  • Plotly, Inc. also provides public, private, and on-premise platforms for publishing graphs, datasets, and interactive Dash applications. More than half of our revenue directly funds open source libraries like these. Learn more about our commercial products.

Much love —

Team Plotly



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store

The low-code framework for rapidly building interactive, scalable data apps in Python.