
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "gallery/text_labels_and_annotations/font_file.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_font_file.py>`
        to download the full example code.

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

.. _sphx_glr_gallery_text_labels_and_annotations_font_file.py:


====================
Using ttf font files
====================

Although it is usually not a good idea to explicitly point to a single ttf file
for a font instance, you can do so by passing a `pathlib.Path` instance as the
*font* parameter.  Note that passing paths as `str`\s is intentionally not
supported, but you can simply wrap `str`\s in `pathlib.Path`\s as needed.

Here, we use the Computer Modern roman font (``cmr10``) shipped with
Matplotlib.

For a more flexible solution, see
:doc:`/gallery/text_labels_and_annotations/font_family_rc` and
:doc:`/gallery/text_labels_and_annotations/fonts_demo`.

.. GENERATED FROM PYTHON SOURCE LINES 18-34

.. code-block:: Python


    from pathlib import Path

    import matplotlib.pyplot as plt

    import matplotlib as mpl

    fig, ax = plt.subplots()

    fpath = Path(mpl.get_data_path(), "fonts/ttf/cmr10.ttf")
    ax.set_title(f'This is a special font: {fpath.name}', font=fpath)
    ax.set_xlabel('This is the default font')

    plt.show()





.. image-sg:: /gallery/text_labels_and_annotations/images/sphx_glr_font_file_001.png
   :alt: This is a special font: cmr10.ttf
   :srcset: /gallery/text_labels_and_annotations/images/sphx_glr_font_file_001.png, /gallery/text_labels_and_annotations/images/sphx_glr_font_file_001_2_00x.png 2.00x
   :class: sphx-glr-single-img





.. GENERATED FROM PYTHON SOURCE LINES 35-41

.. admonition:: References

   The use of the following functions, methods, classes and modules is shown
   in this example:

   - `matplotlib.axes.Axes.set_title`


.. _sphx_glr_download_gallery_text_labels_and_annotations_font_file.py:

.. only:: html

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

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

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

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

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

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

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


.. only:: html

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

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