Matplotlib and Seaborn

Warning

For Pythonic plotting in Deephaven, we recommend Deephaven Express, a real-time version of Plotly Express. It has built-in support for ticking data, more active development, and fewer potential pitfalls when working with ticking plots.

This guide shows you how to use Matplotlib and Seaborn to create plots in Deephaven.

Install the Matplotlib plugin

Use pip to install Deephaven's Matplotlib plugin.

To include Seaborn, run:

The process for installing Python packages depends on whether Deephaven is run from Docker or Pip. See the guide on installing Python packages to learn more.

Matplotlib examples

Static plotting

Caution

All examples in this guide use Matplotlib's explicit interface. Users should do the same, especially in examples where multiple plots source data from ticking tables.

Here is the basic usage of Matplotlib to show one figure:

The above plot

The full functionality of Matplotlib is avilable inside the Deephaven IDE:

Four plots displayed side-by-side

3D plots

Here are some 3D examples. The data, available from Kaggle, needs to be placed in the data directory. For more information see our guide on Docker data volumes.

A 3D scatter plot

A 3D bar graph

The tri_surf 3D graph

Real-time plotting with TableAnimation

Deephaven's matplotlib plugin also enables you to visualize real-time data.

To install the plugin, run:

Making a live animation requires two imports:

The TableAnimation class will re-draw a plot every time a ticking table is updated. It needs three inputs:

  1. The figure containing data (in the examples below, it's fig).
  2. The table containing data (in the examples below, it's tt or tt_sorted_top).
  3. The function defining how the plot is animated (update_fig).

See the examples below.

Line plot

A real-time line chart

Bar plot

A bar chart updating in real time

Scatter plot

Scatter plots require data in a different format than line plots, so we need to pass in the data differently:

The above real-time scatter plot

Multiple series

It's possible to have multiple kinds of series in the same figure. Here is an example of a line and a scatter plot:

Multiple series on the same plot

Seaborn examples

Static plotting

Caution

All examples in this guide use Matplotlib's explicit interface. Users should do the same, especially in examples where there are multiple plots that source data from ticking tables.

Here is the basic usage of Seaborn to show one figure:

The above plots created with Seaborn

Real-time plotting with TableAnimation

Seaborn is designed to plot data from pandas DataFrames. Unlike Matplotlib, we will convert table data to to DataFrames in the update_fig function.

Line plot

A real-time line plot created with Seaborn

Bar plot

A real-time bar plot created with Seaborn

Scatter plot

The above real-time scatter plot created with Seaborn

Multiple series

A multi-series line plot created with Seaborn