.. 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_family_rc.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. meta:: :keywords: codex .. 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_gallery_text_labels_and_annotations_font_family_rc.py: =========================== Configuring the font family =========================== You can explicitly set which font family is picked up, either by specifying family names of fonts installed on user's system, or generic-families (e.g., 'serif', 'sans-serif', 'monospace', 'fantasy' or 'cursive'), or a combination of both. (see :ref:`text_props`) In the example below, we are overriding the default sans-serif generic family to include a specific (Tahoma) font. (Note that the best way to achieve this would simply be to prepend 'Tahoma' in 'font.family') The default family is set with the font.family rcparam, e.g. :: rcParams['font.family'] = 'sans-serif' and for the font.family you set a list of font styles to try to find in order:: rcParams['font.sans-serif'] = ['Tahoma', 'DejaVu Sans', 'Lucida Grande', 'Verdana'] .. redirect-from:: /gallery/font_family_rc_sgskip The ``font.family`` defaults are OS dependent and can be viewed with: .. GENERATED FROM PYTHON SOURCE LINES 31-37 .. code-block:: Python import matplotlib.pyplot as plt print(plt.rcParams["font.sans-serif"][0]) print(plt.rcParams["font.monospace"][0]) .. rst-class:: sphx-glr-script-out .. code-block:: none DejaVu Sans DejaVu Sans Mono .. GENERATED FROM PYTHON SOURCE LINES 38-39 Choose default sans-serif font .. GENERATED FROM PYTHON SOURCE LINES 39-51 .. code-block:: Python def print_text(text): fig, ax = plt.subplots(figsize=(6, 1), facecolor="#eefade") ax.text(0.5, 0.5, text, ha='center', va='center', size=40) ax.axis("off") plt.show() plt.rcParams["font.family"] = "sans-serif" print_text("Hello World! 01") .. image-sg:: /gallery/text_labels_and_annotations/images/sphx_glr_font_family_rc_001.png :alt: font family rc :srcset: /gallery/text_labels_and_annotations/images/sphx_glr_font_family_rc_001.png, /gallery/text_labels_and_annotations/images/sphx_glr_font_family_rc_001_2_00x.png 2.00x :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 52-53 Choose sans-serif font and specify to it to "Nimbus Sans" .. GENERATED FROM PYTHON SOURCE LINES 53-59 .. code-block:: Python plt.rcParams["font.family"] = "sans-serif" plt.rcParams["font.sans-serif"] = ["Nimbus Sans"] print_text("Hello World! 02") .. image-sg:: /gallery/text_labels_and_annotations/images/sphx_glr_font_family_rc_002.png :alt: font family rc :srcset: /gallery/text_labels_and_annotations/images/sphx_glr_font_family_rc_002.png, /gallery/text_labels_and_annotations/images/sphx_glr_font_family_rc_002_2_00x.png 2.00x :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 60-61 Choose default monospace font .. GENERATED FROM PYTHON SOURCE LINES 61-66 .. code-block:: Python plt.rcParams["font.family"] = "monospace" print_text("Hello World! 03") .. image-sg:: /gallery/text_labels_and_annotations/images/sphx_glr_font_family_rc_003.png :alt: font family rc :srcset: /gallery/text_labels_and_annotations/images/sphx_glr_font_family_rc_003.png, /gallery/text_labels_and_annotations/images/sphx_glr_font_family_rc_003_2_00x.png 2.00x :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 67-68 Choose monospace font and specify to it to "FreeMono" .. GENERATED FROM PYTHON SOURCE LINES 68-72 .. code-block:: Python plt.rcParams["font.family"] = "monospace" plt.rcParams["font.monospace"] = ["FreeMono"] print_text("Hello World! 04") .. image-sg:: /gallery/text_labels_and_annotations/images/sphx_glr_font_family_rc_004.png :alt: font family rc :srcset: /gallery/text_labels_and_annotations/images/sphx_glr_font_family_rc_004.png, /gallery/text_labels_and_annotations/images/sphx_glr_font_family_rc_004_2_00x.png 2.00x :class: sphx-glr-single-img .. _sphx_glr_download_gallery_text_labels_and_annotations_font_family_rc.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: font_family_rc.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: font_family_rc.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_