.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/plot_07_theme.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_gallery_plot_07_theme.py: Themes and backgrounds ====================== A Reveal.js theme sets the fonts and colours, custom CSS adjusts them, and ``data-background-*`` arguments give a slide its own background, which covers the whole window on screen. .. GENERATED FROM PYTHON SOURCE LINES 9-15 .. code-block:: Python import plotly.express as px from markdown import markdown from respysive import Presentation, Slide .. GENERATED FROM PYTHON SOURCE LINES 16-22 A dark deck ----------- The ``night`` theme is dark. Reveal.js themes read CSS variables such as ``--r-background-color``, so redefining them recolours every slide. A slide class (``branded``) lets the CSS add a label to some slides only. .. GENERATED FROM PYTHON SOURCE LINES 22-58 .. code-block:: Python CSS = """ :root { --r-background-color: #0b2545; --r-main-color: #eef4ed; --r-heading-color: #ffffff; --r-heading-text-transform: none; } .reveal .slides section.branded::after { content: "World health, 2007"; position: absolute; right: 30px; bottom: 18px; font-size: 18px; opacity: 0.6; } """ df = px.data.gapminder().query("year == 2007") fig = px.box( df, x="continent", y="lifeExp", color="continent", points="all", template="plotly_dark", color_discrete_sequence=["#8da9c4", "#f4a261", "#e63946", "#2a9d8f", "#eef4ed"], labels={"continent": "", "lifeExp": "Life expectancy (years)"}, ) fig.update_layout(height=500, margin=dict(l=10, r=10, t=10, b=10), showlegend=False, paper_bgcolor="rgba(0,0,0,0)", plot_bgcolor="rgba(0,0,0,0)") dark = Slide(**{"class": "branded"}) spread = df.groupby("continent")["lifeExp"].agg(lambda s: s.max() - s.min()) dark.add_title(f"Within Asia, life expectancy spans {spread['Asia']:.0f} years, within Europe {spread['Europe']:.0f}") dark.add_content([fig]) .. GENERATED FROM PYTHON SOURCE LINES 59-64 Slide backgrounds ----------------- A colour, a gradient, or an image. Images are embedded in the HTML file, and ``data-background-opacity`` dims them behind the text. .. GENERATED FROM PYTHON SOURCE LINES 64-86 .. code-block:: Python gradient = Slide( center=True, **{"data-background-gradient": "linear-gradient(135deg, #0b2545 0%, #8da9c4 100%)"} ) gradient.add_title("Does income explain longer lives?", tag="h2") gradient.add_content([markdown("The next slides compare income and life expectancy, country by country.")]) image = Slide( center=True, **{ "data-background-image": "data/life_curves.png", "data-background-size": "cover", "data-background-opacity": "0.15", }, ) image.add_title("Thank you", tag="h2") image.add_content([markdown("Gapminder data, 1952-2007")]) deck = Presentation() deck.add_custom_css(CSS) deck.add_slide([dark, gradient, image]) deck.save_html("theme.html", theme="night", transition="fade") .. raw:: html
Click the slide, then use the arrow keys.
.. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 7.967 seconds) .. _sphx_glr_download_gallery_plot_07_theme.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_07_theme.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_07_theme.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_07_theme.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_