.. 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 Click :ref:`here ` 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 :doc:`font tutorial `) 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:: /examples/font_family_rc_sgskip The font font.family defaults are OS dependent and can be viewed with .. GENERATED FROM PYTHON SOURCE LINES 33-39 .. code-block:: default 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 40-41 Choose default sans-serif font .. GENERATED FROM PYTHON SOURCE LINES 41-53 .. code-block:: default 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_0x.png 2.0x :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 54-55 Choose sans-serif font and specify to it to "Nimbus Sans" .. GENERATED FROM PYTHON SOURCE LINES 55-61 .. code-block:: default 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_0x.png 2.0x :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 62-63 Choose default monospace font .. GENERATED FROM PYTHON SOURCE LINES 63-68 .. code-block:: default 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_0x.png 2.0x :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 69-70 Choose monospace font and specify to it to "FreeMono" .. GENERATED FROM PYTHON SOURCE LINES 70-74 .. code-block:: default 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_0x.png 2.0x :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-python :download:`Download Python source code: font_family_rc.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: font_family_rc.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_