.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/plot_08_overflow.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_08_overflow.py: Content taller than the slide ============================= A slide is 1280 x 720 pixels. When its content is taller, respysive fits it: the text shrinks first, down to 60% of its size, then the whole content scales down. The layout stays the same on screen, in PDF, and in PowerPoint. .. GENERATED FROM PYTHON SOURCE LINES 10-33 .. code-block:: Python import plotly.express as px from respysive import Presentation, Slide STYLE = """ :root { --r-heading-color: #1d3557; --r-heading-text-transform: none; } .reveal table { font-size: 22px; } """ px.defaults.template = "plotly_white" latest = px.data.gapminder().query("year == 2007") populated = latest.nlargest(15, "pop") table = ( populated[["country", "continent", "pop", "lifeExp"]] .assign(pop=lambda d: (d["pop"] / 1e6).round(1), lifeExp=lambda d: d["lifeExp"].round(1)) .rename(columns={"country": "Country", "continent": "Continent", "pop": "Population (millions)", "lifeExp": "Life expectancy"}) .set_index("Country") ) .. GENERATED FROM PYTHON SOURCE LINES 34-40 A long table ------------ Fifteen rows do not fit at full size. The text shrinks until they do, while the title keeps its size. A pandas ``DataFrame`` is inserted as an HTML table. .. GENERATED FROM PYTHON SOURCE LINES 40-45 .. code-block:: Python long = Slide() long.add_title(f"{(populated['lifeExp'] >= 70).sum()} of the {len(populated)} most populated countries live past 70 years") long.add_content([table]) .. GENERATED FROM PYTHON SOURCE LINES 46-51 A table next to a chart ----------------------- Shrinking the text is not enough when a chart is tall too. The whole content then scales down, like a picture, and keeps its layout. .. GENERATED FROM PYTHON SOURCE LINES 51-67 .. code-block:: Python bars = px.bar( populated.sort_values("lifeExp"), x="lifeExp", y="country", orientation="h", color_discrete_sequence=["#457b9d"], labels={"lifeExp": "Life expectancy (years)", "country": ""}, ) bars.update_layout(height=640, margin=dict(l=10, r=10, t=10, b=10)) both = Slide() longest, shortest = populated.nlargest(1, "lifeExp").iloc[0], populated.nsmallest(1, "lifeExp").iloc[0] both.add_title(f"{longest.country} lives {longest.lifeExp - shortest.lifeExp:.0f} years longer than {shortest.country}") both.add_content([table, bars], columns=[7, 5]) .. GENERATED FROM PYTHON SOURCE LINES 68-71 The fitting can be turned off with ``Slide(overflow="visible")``, or reported in the browser console only with ``overflow="warn"``. ``save_html(overflow=...)`` sets the behaviour of every slide. .. GENERATED FROM PYTHON SOURCE LINES 71-77 .. code-block:: Python deck = Presentation() deck.add_custom_css(STYLE) deck.add_slide([long, both]) deck.save_html("overflow.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 6.293 seconds) .. _sphx_glr_download_gallery_plot_08_overflow.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_08_overflow.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_08_overflow.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_08_overflow.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_