Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Themes

The complete source code for the following examples can also be found here.

Use different theme templates

Similar to Plotly Python templates, plotly.rs provides several built-in themes that can be applied to your plots.

#![allow(unused)]
fn main() {
use plotly::{
    common::{Marker, Mode, Title},
    layout::{Layout, BuiltinTheme},
    Plot, Scatter,
};
}

The to_inline_html method is used to produce the html plot displayed in this page.

Default Theme (Plotly)

Plotly White Theme

Plotly Dark Theme

Seaborn Theme

Matplotlib Theme

Plotnine Theme

Available Themes

The following built-in themes are available in plotly.rs:

  • BuiltinTheme::Default - Default Plotly theme
  • BuiltinTheme::PlotlyWhite - Clean white background theme
  • BuiltinTheme::PlotlyDark - Dark theme
  • BuiltinTheme::Seaborn - Seaborn-style theme
  • BuiltinTheme::SeabornWhitegrid - Seaborn with white grid
  • BuiltinTheme::SeabornDark - Dark Seaborn theme
  • BuiltinTheme::Matplotlib - Matplotlib-style theme
  • BuiltinTheme::Plotnine - Plotnine-style theme

Using Themes

To apply a theme to your plot, use the template() method on the layout:

#![allow(unused)]
fn main() {
let theme = BuiltinTheme::Seaborn;
let layout = Layout::new().template(theme.build());
plot.set_layout(layout);
}

The example above uses real Gapminder 2007 data showing the relationship between GDP per capita, life expectancy, and population size across different continents, with marker sizes representing population and colors representing continents.