The complete source code for the following examples can also be found here.
Similar to Plotly Python templates, plotly.rs provides several built-in themes that can be applied to your plots.
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.
{{#include ../../../../examples/themes/output/inline_gapminder_plotly.html}}
{{#include ../../../../examples/themes/output/inline_gapminder_plotly_white.html}}
{{#include ../../../../examples/themes/output/inline_gapminder_plotly_dark.html}}
{{#include ../../../../examples/themes/output/inline_gapminder_seaborn.html}}
{{#include ../../../../examples/themes/output/inline_gapminder_matplotlib.html}}
{{#include ../../../../examples/themes/output/inline_gapminder_plotnine.html}}
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
To apply a theme to your plot, use the template() method on the layout:
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.