
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "gallery/text_labels_and_annotations/fonts_demo.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. meta::
        :keywords: codex

    .. note::
        :class: sphx-glr-download-link-note

        :ref:`Go to the end <sphx_glr_download_gallery_text_labels_and_annotations_fonts_demo.py>`
        to download the full example code.

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_gallery_text_labels_and_annotations_fonts_demo.py:


==================================
Fonts demo (object-oriented style)
==================================

Set font properties using setters.

See :doc:`fonts_demo_kw` to achieve the same effect using keyword arguments.

.. GENERATED FROM PYTHON SOURCE LINES 10-65



.. image-sg:: /gallery/text_labels_and_annotations/images/sphx_glr_fonts_demo_001.png
   :alt: fonts demo
   :srcset: /gallery/text_labels_and_annotations/images/sphx_glr_fonts_demo_001.png, /gallery/text_labels_and_annotations/images/sphx_glr_fonts_demo_001_2_00x.png 2.00x
   :class: sphx-glr-single-img





.. code-block:: Python


    import matplotlib.pyplot as plt

    from matplotlib.font_manager import FontProperties

    fig = plt.figure()
    alignment = {'horizontalalignment': 'center', 'verticalalignment': 'baseline'}
    yp = [0.8, 0.7, 0.6, 0.5, 0.4, 0.3, 0.2]
    heading_font = FontProperties(size='large')

    # Show family options
    fig.text(0.1, 0.9, 'family', fontproperties=heading_font, **alignment)
    families = ['serif', 'sans-serif', 'cursive', 'fantasy', 'monospace']
    for k, family in enumerate(families):
        font = FontProperties(family=[family])
        fig.text(0.1, yp[k], family, fontproperties=font, **alignment)

    # Show style options
    styles = ['normal', 'italic', 'oblique']
    fig.text(0.3, 0.9, 'style', fontproperties=heading_font, **alignment)
    for k, style in enumerate(styles):
        font = FontProperties(family='sans-serif', style=style)
        fig.text(0.3, yp[k], style, fontproperties=font, **alignment)

    # Show variant options
    variants = ['normal', 'small-caps']
    fig.text(0.5, 0.9, 'variant', fontproperties=heading_font, **alignment)
    for k, variant in enumerate(variants):
        font = FontProperties(family='serif', variant=variant)
        fig.text(0.5, yp[k], variant, fontproperties=font, **alignment)

    # Show weight options
    weights = ['light', 'normal', 'medium', 'semibold', 'bold', 'heavy', 'black']
    fig.text(0.7, 0.9, 'weight', fontproperties=heading_font, **alignment)
    for k, weight in enumerate(weights):
        font = FontProperties(weight=weight)
        fig.text(0.7, yp[k], weight, fontproperties=font, **alignment)

    # Show size options
    sizes = [
        'xx-small', 'x-small', 'small', 'medium', 'large', 'x-large', 'xx-large']
    fig.text(0.9, 0.9, 'size', fontproperties=heading_font, **alignment)
    for k, size in enumerate(sizes):
        font = FontProperties(size=size)
        fig.text(0.9, yp[k], size, fontproperties=font, **alignment)

    # Show bold italic
    font = FontProperties(style='italic', weight='bold', size='x-small')
    fig.text(0.3, 0.1, 'bold italic', fontproperties=font, **alignment)
    font = FontProperties(style='italic', weight='bold', size='medium')
    fig.text(0.3, 0.2, 'bold italic', fontproperties=font, **alignment)
    font = FontProperties(style='italic', weight='bold', size='x-large')
    fig.text(0.3, 0.3, 'bold italic', fontproperties=font, **alignment)

    plt.show()


.. _sphx_glr_download_gallery_text_labels_and_annotations_fonts_demo.py:

.. only:: html

  .. container:: sphx-glr-footer sphx-glr-footer-example

    .. container:: sphx-glr-download sphx-glr-download-jupyter

      :download:`Download Jupyter notebook: fonts_demo.ipynb <fonts_demo.ipynb>`

    .. container:: sphx-glr-download sphx-glr-download-python

      :download:`Download Python source code: fonts_demo.py <fonts_demo.py>`

    .. container:: sphx-glr-download sphx-glr-download-zip

      :download:`Download zipped: fonts_demo.zip <fonts_demo.zip>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
