|
| 1 | +# Themes |
| 2 | + |
| 3 | +The complete source code for the following examples can also be found [here](https://github.com/plotly/plotly.rs/tree/main/examples/themes). |
| 4 | + |
| 5 | +# Use different theme templates |
| 6 | + |
| 7 | +Similar to [Plotly Python templates](https://plotly.com/python/templates/), plotly.rs provides several built-in themes that can be applied to your plots. |
| 8 | + |
| 9 | +```rust,no_run |
| 10 | +use plotly::{ |
| 11 | + common::{Marker, Mode, Title}, |
| 12 | + layout::{Layout, BuiltinTheme}, |
| 13 | + Plot, Scatter, |
| 14 | +}; |
| 15 | +``` |
| 16 | + |
| 17 | +The `to_inline_html` method is used to produce the html plot displayed in this page. |
| 18 | + |
| 19 | +## Default Theme (Plotly) |
| 20 | + |
| 21 | +{{#include ../../../../examples/themes/output/inline_gapminder_plotly.html}} |
| 22 | + |
| 23 | +## Plotly White Theme |
| 24 | + |
| 25 | +{{#include ../../../../examples/themes/output/inline_gapminder_plotly_white.html}} |
| 26 | + |
| 27 | +## Plotly Dark Theme |
| 28 | + |
| 29 | +{{#include ../../../../examples/themes/output/inline_gapminder_plotly_dark.html}} |
| 30 | + |
| 31 | +## Seaborn Theme |
| 32 | + |
| 33 | +{{#include ../../../../examples/themes/output/inline_gapminder_seaborn.html}} |
| 34 | + |
| 35 | +## Matplotlib Theme |
| 36 | + |
| 37 | +{{#include ../../../../examples/themes/output/inline_gapminder_matplotlib.html}} |
| 38 | + |
| 39 | +## Plotnine Theme |
| 40 | + |
| 41 | +{{#include ../../../../examples/themes/output/inline_gapminder_plotnine.html}} |
| 42 | + |
| 43 | +## Available Themes |
| 44 | + |
| 45 | +The following built-in themes are available in plotly.rs: |
| 46 | + |
| 47 | +- `BuiltinTheme::Default` - Default Plotly theme |
| 48 | +- `BuiltinTheme::PlotlyWhite` - Clean white background theme |
| 49 | +- `BuiltinTheme::PlotlyDark` - Dark theme |
| 50 | +- `BuiltinTheme::Seaborn` - Seaborn-style theme |
| 51 | +- `BuiltinTheme::SeabornWhitegrid` - Seaborn with white grid |
| 52 | +- `BuiltinTheme::SeabornDark` - Dark Seaborn theme |
| 53 | +- `BuiltinTheme::Matplotlib` - Matplotlib-style theme |
| 54 | +- `BuiltinTheme::Plotnine` - Plotnine-style theme |
| 55 | + |
| 56 | +## Using Themes |
| 57 | + |
| 58 | +To apply a theme to your plot, use the `template()` method on the layout: |
| 59 | + |
| 60 | +```rust |
| 61 | +let theme = BuiltinTheme::Seaborn; |
| 62 | +let layout = Layout::new().template(theme.build()); |
| 63 | +plot.set_layout(layout); |
| 64 | +``` |
| 65 | + |
| 66 | +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. |
0 commit comments