.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/example_annotation_box.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_example_annotation_box.py: ================================ mpl-simple-svg-parser with AnnotationBbox ================================ .. GENERATED FROM PYTHON SOURCE LINES 7-72 .. image-sg:: /examples/images/sphx_glr_example_annotation_box_001.png :alt: TIOBE Score 2023 :srcset: /examples/images/sphx_glr_example_annotation_box_001.png :class: sphx-glr-single-img .. code-block:: Python import matplotlib.pyplot as plt from matplotlib.offsetbox import AnnotationBbox from mpl_simple_svg_parser import SVGMplPathIterator import seaborn as sns import pandas as pd # TIOBE score from https://spectrum.ieee.org/the-top-programming-languages-2023 l = [ ("Python", 1), ("Java", 0.588), ("C++", 0.538), ("C", 0.4641), ("JavaScript", 0.4638), ("C#", 0.3973) ] df = pd.DataFrame(l, columns=["language", "score"]) sns.set_color_codes("muted") sns.set(font_scale = 1.5) fig, ax = plt.subplots(num=1, clear=True, layout="constrained") sns.barplot(x="score", y="language", data=df, label="Tiobe Score 2023", color="b") ax.yaxis.label.set_visible(False) ax.set_title("TIOBE Score 2023") # svg icons of selected language, downloaded from https://www.svgrepo.com. icons = { "python": b'''file_type_python''', 'java': b'''file_type_java''', "javascript": b'''file_type_js''', 'c': b'''file_type_c3''', 'c#': b'''file_type_csharp2''', "c++": b'''file_type_cpp3''' } def get_icon(language, ax, wmax=64, hmax=64): icon_svg = icons[language.lower()] svg_mpl_path_iterator = SVGMplPathIterator(icon_svg) da = svg_mpl_path_iterator.get_drawing_area(ax, wmax=wmax, hmax=hmax) return da for l, bar in zip(ax.get_yticklabels(), ax.containers[0]): language = l.get_text().lower() da = get_icon(language, ax, hmax=32) ab = AnnotationBbox(da, (1., 0.5), xycoords=bar, frameon=False, xybox=(5, 0), boxcoords="offset points", box_alignment=(0.0, 0.5)) ax.add_artist(ab) ax.set_xlim(0, 1.13) plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.954 seconds) .. _sphx_glr_download_examples_example_annotation_box.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: example_annotation_box.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: example_annotation_box.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_