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 themeBuiltinTheme::PlotlyWhite
- Clean white background themeBuiltinTheme::PlotlyDark
- Dark themeBuiltinTheme::Seaborn
- Seaborn-style themeBuiltinTheme::SeabornWhitegrid
- Seaborn with white gridBuiltinTheme::SeabornDark
- Dark Seaborn themeBuiltinTheme::Matplotlib
- Matplotlib-style themeBuiltinTheme::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.