.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/demo_3d_cylinder.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_examples_demo_3d_cylinder.py: ==================== Cylinder bar chart ==================== .. GENERATED FROM PYTHON SOURCE LINES 7-63 .. image-sg:: /examples/images/sphx_glr_demo_3d_cylinder_001.png :alt: demo 3d cylinder :srcset: /examples/images/sphx_glr_demo_3d_cylinder_001.png :class: sphx-glr-single-img .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from matplotlib.transforms import Affine2D import seaborn as sns penguins = sns.load_dataset("penguins") # Draw a nested barplot by species and sex g = sns.catplot( data=penguins, kind="bar", x="species", y="body_mass_g", hue="sex", errorbar=None, height=6, ) g.despine(left=True) g.set_axis_labels("", "Body mass (g)") g.legend.set_title("") # Now we convert bars to prisms. from matplotlib.colors import LightSource from mpl_poormans_3d import BarToPrism, BarToCylinder ax = g.ax ax.set_ylim(ymin=-300) ls = LightSource(azdeg=25) max_height=6000 colors=[None, "w", None, "w"] * 8 rgbFace=None # affines=[(Affine2D().translate(10, -10).scale(0.5), Affine2D().translate(10, -10)), # (Affine2D(), Affine2D().scale(0.5))] affines=[(Affine2D().translate(0, 0), Affine2D().translate(0, 0)), (Affine2D().translate(5, 0), Affine2D().translate(5, 0)), (Affine2D().translate(0, 0), Affine2D().translate(0, 0)), (Affine2D().translate(-5, 0), Affine2D().translate(-5, 0)), ] * 8 segment_params = (ax, max_height, colors, rgbFace, affines) segment_params = None bar_to_prism = BarToPrism(ls, 4, scale=0.9, rotate_deg=20) # bar_to_prism = BarToCylinder(ls, scale=0.8, segment_params=segment_params, # fraction=0.3) for i, p in enumerate(ax.containers[0]): p.set_path_effects([bar_to_prism]) for i, p in enumerate(ax.containers[1]): p.set_path_effects([bar_to_prism]) plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.386 seconds) .. _sphx_glr_download_examples_demo_3d_cylinder.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: demo_3d_cylinder.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: demo_3d_cylinder.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_