Jupyter Support

As of version 0.6.0, Plotly.rs has native support for the EvCxR Jupyter Kernel.

Once you've installed the required packages you'll be able to run all the examples shown here as well as all the recipes in Jupyter Lab!


It is assumed that an installation of the Anaconda Python distribution is already present in the system. If that is not the case you can follow these instructions to get up and running with Anaconda.

conda install -c plotly plotly=4.9.0
conda install jupyterlab "ipywidgets=7.5"

optionally (or instead of jupyterlab) you can also install Jupyter Notebook:

conda install notebook

Although there are alternative methods to enable support for the EvCxR Jupyter Kernel, we have elected to keep the requirements consistent with what those of other languages, e.g. Julia, Python and R. This way users know what to expect; and also the folks at Plotly have done already most of the heavy lifting to create an extension for Jupyter Lab that works very well.

Run the following to install the Plotly Jupyter Lab extension:

jupyter labextension install jupyterlab-plotly@4.9.0

Once this step is complete to make sure the installation so far was successful, run the following command:

jupyter lab

Open a Python 3 kernel copy/paste the following code in a cell and run it:

import plotly.graph_objects as go
fig = go.Figure(data=go.Bar(x=['a', 'b', 'c'], y=[11, 22, 33]))

You should see the following figure:

Next you need to install the EvCxR Jupyter Kernel. Note that EvCxR requires CMake as it has to compile ZMQ. If CMake is already installed on your system and is in your path (to test that simply run cmake --version if that returns a version you're good to go) then continue to the next steps.

In a command line execute the following commands:

cargo install evcxr_jupyter
evcxr_jupyter --install

If you're not familiar with the EvCxR kernel it would be good that you at least glance over the EvCxR Jupyter Tour.


Launch Jupyter Lab:

jupyter lab

create a new notebook and select the Rust kernel. Then create the following three cells and execute them in order:

:dep plotly = { version = ">=0.6.0" }
:dep itertools-num = "0.1.3"

fn main() {
extern crate plotly;
extern crate rand_distr;
extern crate itertools_num;
extern crate itertools;

fn main() {
use itertools_num::linspace;
use plotly::common::{
    ColorScale, ColorScalePalette, DashType, Fill, Font, Line, LineShape, Marker, Mode, Title,
use plotly::layout::{Axis, BarMode, Layout, Legend, TicksDirection};
use plotly::{Bar, NamedColor, Plot, Rgb, Rgba, Scatter};
use rand_distr::{Distribution, Normal, Uniform};

Now we're ready to start plotting!

fn main() {
let n: usize = 100;
let t: Vec<f64> = linspace(0., 10., n).collect();
let y: Vec<f64> = t.iter().map(|x| x.sin()).collect();

let trace = Scatter::new(t, y).mode(Mode::Markers);
let mut plot = Plot::new();
let layout = Layout::new().height(800);

For Jupyter Lab there are two ways to display a plot in the EvCxR kernel, either have the plot object be in the last line without a semicolon or directly invoke the Plot::lab_display method on it; both have the same result. You can also find an example notebook here that will periodically be updated with examples.

The process for Jupyter Notebook is very much the same with one exception; the Plot::noteboo_display method must be used to display the plot. You can find an example notebook here