.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/ribbonbox_notebook.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_ribbonbox_notebook.py: ==================== Demo of SVG bar chart ==================== .. GENERATED FROM PYTHON SOURCE LINES 6-155 .. rst-class:: sphx-glr-horizontal * .. image-sg:: /examples/images/sphx_glr_ribbonbox_notebook_001.png :alt: ribbonbox notebook :srcset: /examples/images/sphx_glr_ribbonbox_notebook_001.png :class: sphx-glr-multi-img * .. image-sg:: /examples/images/sphx_glr_ribbonbox_notebook_002.png :alt: ribbonbox notebook :srcset: /examples/images/sphx_glr_ribbonbox_notebook_002.png :class: sphx-glr-multi-img * .. image-sg:: /examples/images/sphx_glr_ribbonbox_notebook_003.png :alt: ribbonbox notebook :srcset: /examples/images/sphx_glr_ribbonbox_notebook_003.png :class: sphx-glr-multi-img * .. image-sg:: /examples/images/sphx_glr_ribbonbox_notebook_004.png :alt: ribbonbox notebook :srcset: /examples/images/sphx_glr_ribbonbox_notebook_004.png :class: sphx-glr-multi-img .. code-block:: Python # Let's try to read gift-pack-svgrepo-com2.svg # https://www.svgrepo.com/svg/368437/gift-pack xmlstring = b""" gift-pack """ from mpl_simple_svg_parser import SVGMplPathIterator, get_paths_extents from mpl_pe_fancy_bar import PathsStretcher from mpl_pe_fancy_bar.paths_stretcher import ( get_normalizing_transform, show_paths_with_gc_prop, show_paths_with_patch_prop ) import matplotlib.pyplot as plt if True: svg = SVGMplPathIterator(xmlstring) paths = list(svg.iter_mpl_path_patch_prop()) fig, ax = plt.subplots(1, 1, num=1, clear=True) ax.set_aspect(True) show_paths_with_patch_prop(ax, paths) bb = get_paths_extents([p for p, _ in paths]) tr, height = get_normalizing_transform(bb) paths = [(tr.transform_path(p), _) for (p, _) in paths] fig, ax = plt.subplots(1, 1, num=2, clear=True) ax.set_aspect(True) show_paths_with_patch_prop(ax, paths, show_i=True) plt.show() def get_ribbonbox_drawer(): svg = SVGMplPathIterator(xmlstring) paths = list(svg.iter_mpl_path_patch_prop()) bb = get_paths_extents([p for p, _ in paths]) tr, height = get_normalizing_transform(bb) paths = [(tr.transform_path(p), _) for (p, _) in paths] def get_color(i, p, fc, ec, fc_new, ec_new): if i == 0: return fc_new, ec return fc, ec # we use height of the box without the ribbon part at the top. ribbonbox_drawer = PathsStretcher(paths, height-0.3, y_thresh=0.4, height_lim=0.4, fn_get_color=get_color) return ribbonbox_drawer if True: ribbonbox_drawer = get_ribbonbox_drawer() paths = ribbonbox_drawer(3.4, "y") fig, ax = plt.subplots(1, 1, num=5, clear=True) ax.set_aspect(True) show_paths_with_gc_prop(ax, paths) plt.show() if True: import numpy as np import matplotlib.pyplot as plt from matplotlib.patheffects import Normal import mpl_visual_context.patheffects as pe np.random.seed(19680) # Example data n = 4 x_pos = np.arange(n) performance = 5 * np.random.rand(n) colors = [f"C{i}" for i in range(n)] fig, ax = plt.subplots(1, 1, num=6, clear=True) bars = ax.bar(x_pos, performance, align='center', alpha=0.7, color=colors) drawer = get_ribbonbox_drawer() # from mpl_visual_context.patheffects_path import BarTransformFromFunc from mpl_pe_fancy_bar import BarToMultiplePaths #BarTransformFromFunc pe1 = BarToMultiplePaths(drawer) for p in bars: p.set_path_effects([pe1]) plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 2.848 seconds) .. _sphx_glr_download_examples_ribbonbox_notebook.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: ribbonbox_notebook.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: ribbonbox_notebook.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_