.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/plot_01_first_deck.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_01_first_deck.py: A first presentation ==================== Three slides on world health: a title page, a text slide written in Markdown, and a chart with its comment. The whole deck is one HTML file that opens in any browser. .. 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 house style ------------- The Reveal.js ``white`` theme gives the fonts. Three CSS variables give the colours and remove the capitals of the titles. Plotly charts follow with a white template and the same palette. .. GENERATED FROM PYTHON SOURCE LINES 22-38 .. code-block:: Python STYLE = """ :root { --r-heading-color: #1d3557; --r-heading-text-transform: none; --r-link-color: #e63946; } """ PALETTE = ["#1d3557", "#e63946", "#457b9d", "#f4a261", "#2a9d8f"] px.defaults.template = "plotly_white" px.defaults.color_discrete_sequence = PALETTE gapminder = px.data.gapminder() first_year, last_year = gapminder["year"].min(), gapminder["year"].max() n_countries = gapminder["country"].nunique() .. GENERATED FROM PYTHON SOURCE LINES 39-45 Title page ---------- ``add_title_page`` takes a title, a subtitle, and authors. ``styles`` gives the CSS of each, in that order. The gradient is a slide background, which covers the whole screen. .. GENERATED FROM PYTHON SOURCE LINES 45-56 .. code-block:: Python title = Slide(center=True, **{"data-background-gradient": "linear-gradient(135deg, #1d3557, #457b9d)"}) title.add_title_page( {"title": "World health in 2007", "subtitle": "Life expectancy and income", "authors": "Gapminder data"}, styles=[ {"color": "#ffffff", "font-size": "88px"}, {"color": "#a8dadc", "font-size": "44px"}, {"color": "#f1faee", "font-size": "28px"}, ], ) .. GENERATED FROM PYTHON SOURCE LINES 57-62 Text slide ---------- Markdown is converted with the ``markdown`` package. The icon is a `Font Awesome `_ class. .. GENERATED FROM PYTHON SOURCE LINES 62-80 .. code-block:: Python text = Slide() text.add_title(f"{n_countries} countries followed from {first_year} to {last_year}", icon="fas fa-earth-africa") text.add_content( [ markdown( """ The Gapminder data set gives one value every five years for each country. - Life expectancy at birth, in years - GDP per capita, in US dollars adjusted for inflation - Population """ ) ] ) text.add_notes("The data set ships with Plotly: px.data.gapminder().") .. GENERATED FROM PYTHON SOURCE LINES 81-87 A chart and its comment ----------------------- ``columns`` shares the 12 columns of the slide: 8 for the chart, 4 for the text. The chart stays interactive: hover a bubble to read the country. .. GENERATED FROM PYTHON SOURCE LINES 87-118 .. code-block:: Python df = gapminder.query("year == @last_year") first, last = df.nlargest(1, "lifeExp").iloc[0], df.nsmallest(1, "lifeExp").iloc[0] fig = px.scatter( df, x="gdpPercap", y="lifeExp", size="pop", color="continent", hover_name="country", log_x=True, size_max=45, labels={"gdpPercap": "GDP per capita (USD, log scale)", "lifeExp": "Life expectancy (years)", "continent": ""}, ) fig.update_layout(height=540, margin=dict(l=10, r=10, t=10, b=10), legend=dict(orientation="h", y=1.08)) chart = Slide() chart.add_title(f"Richer countries live longer, {last_year}") chart.add_content( [ fig, markdown( f"{first.country} leads with **{first.lifeExp:.1f} years**.\n\n" f"{last.country} comes last with **{last.lifeExp:.1f} years**, " f"{first.lifeExp - last.lifeExp:.0f} years less." ), ], columns=[8, 4], styles=[None, {"font-size": "75%", "align-self": "center"}], ) .. GENERATED FROM PYTHON SOURCE LINES 119-123 Saving ------ Slides are added in order, then ``save_html`` writes the file. .. GENERATED FROM PYTHON SOURCE LINES 123-129 .. code-block:: Python deck = Presentation() deck.add_custom_css(STYLE) deck.add_slide([title, text, chart]) deck.save_html("first_deck.html", theme="white") .. raw:: html
Click the slide, then use the arrow keys.
.. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 9.812 seconds) .. _sphx_glr_download_gallery_plot_01_first_deck.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_01_first_deck.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_01_first_deck.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_01_first_deck.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_