Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 02f2ea7

Browse files
authored
Merge pull request #20346 from aitikgupta/font-docs
Clarify/Improve docs on family-names vs generic-families
2 parents 3cf46cb + 61abd44 commit 02f2ea7

File tree

2 files changed

+47
-16
lines changed

2 files changed

+47
-16
lines changed

examples/text_labels_and_annotations/font_family_rc_sgskip.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,17 @@
33
Configuring the font family
44
===========================
55
6-
You can explicitly set which font family is picked up for a given font
7-
style (e.g., 'serif', 'sans-serif', or 'monospace').
6+
You can explicitly set which font family is picked up, either by specifying
7+
family names of fonts installed on user's system, or generic-families
8+
(e.g., 'serif', 'sans-serif', 'monospace', 'fantasy' or 'cursive'),
9+
or a combination of both.
10+
(see :doc:`font tutorial </tutorials/text/text_props>`)
811
9-
In the example below, we only allow one font family (Tahoma) for the
10-
sans-serif font style. The default family is set with the font.family rcparam,
12+
In the example below, we are overriding the default sans-serif generic family
13+
to include a specific (Tahoma) font. (Note that the best way to achieve this
14+
would simply be to prepend 'Tahoma' in 'font.family')
15+
16+
The default family is set with the font.family rcparam,
1117
e.g. ::
1218
1319
rcParams['font.family'] = 'sans-serif'

tutorials/text/text_props.py

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,9 @@
149149
# +---------------------+----------------------------------------------------+
150150
# | rcParam | usage |
151151
# +=====================+====================================================+
152-
# | ``'font.family'`` | List of either names of font or ``{'cursive', |
153-
# | | 'fantasy', 'monospace', 'sans', 'sans serif', |
154-
# | | 'sans-serif', 'serif'}``. |
152+
# | ``'font.family'`` | List of font families (installed on user's machine)|
153+
# | | and/or ``{'cursive', 'fantasy', 'monospace', |
154+
# | | 'sans', 'sans serif', 'sans-serif', 'serif'}``. |
155155
# | | |
156156
# +---------------------+----------------------------------------------------+
157157
# | ``'font.style'`` | The default style, ex ``'normal'``, |
@@ -174,13 +174,18 @@
174174
# | | this size. |
175175
# +---------------------+----------------------------------------------------+
176176
#
177-
# The mapping between the family aliases (``{'cursive', 'fantasy',
178-
# 'monospace', 'sans', 'sans serif', 'sans-serif', 'serif'}``) and actual font names
177+
# Matplotlib can use font families installed on the user's computer, i.e.
178+
# Helvetica, Times, etc. Font families can also be specified with
179+
# generic-family aliases like (``{'cursive', 'fantasy', 'monospace',
180+
# 'sans', 'sans serif', 'sans-serif', 'serif'}``).
181+
#
182+
# The mapping between the generic family aliases and actual font families
183+
# (mentioned at :doc:`default rcParams </tutorials/introductory/customizing>`)
179184
# is controlled by the following rcParams:
180185
#
181186
#
182187
# +------------------------------------------+--------------------------------+
183-
# | family alias | rcParam with mappings |
188+
# | CSS-based generic-family alias | rcParam with mappings |
184189
# +==========================================+================================+
185190
# | ``'serif'`` | ``'font.serif'`` |
186191
# +------------------------------------------+--------------------------------+
@@ -194,7 +199,15 @@
194199
# +------------------------------------------+--------------------------------+
195200
#
196201
#
197-
# which are lists of font names.
202+
# If any of generic family names appear in ``'font.family'``, we replace that entry
203+
# by all the entries in the corresponding rcParam mapping.
204+
# For example: ::
205+
#
206+
# matplotlib.rcParams['font.family'] = ['Family1', 'serif', 'Family2']
207+
# matplotlib.rcParams['font.serif'] = ['SerifFamily1', 'SerifFamily2']
208+
#
209+
# # This is effectively translated to:
210+
# matplotlib.rcParams['font.family'] = ['Family1', 'SerifFamily1', 'SerifFamily2', 'Family2']
198211
#
199212
# Text with non-latin glyphs
200213
# ==========================
@@ -204,14 +217,26 @@
204217
# Korean, or Japanese.
205218
#
206219
# To set the default font to be one that supports the code points you
207-
# need, prepend the font name to ``'font.family'`` or the desired alias
208-
# lists ::
220+
# need, prepend the font name to ``'font.family'`` (recommended), or to the
221+
# desired alias lists. ::
222+
#
223+
# # first method
224+
# matplotlib.rcParams['font.family'] = ['Source Han Sans TW', 'sans-serif']
225+
#
226+
# # second method
227+
# matplotlib.rcParams['font.family'] = ['sans-serif']
228+
# matplotlib.rcParams['sans-serif'] = ['Source Han Sans TW', ...]
229+
#
230+
# The generic family alias lists contain fonts that are either shipped
231+
# alongside Matplotlib (so they have 100% chance of being found), or fonts
232+
# which have a very high probability of being present in most systems.
209233
#
210-
# matplotlib.rcParams['font.sans-serif'] = ['Source Han Sans TW', 'sans-serif']
234+
# A good practice when setting custom font families is to append
235+
# a generic-family to the font-family list as a last resort.
211236
#
212-
# or set it in your :file:`.matplotlibrc` file::
237+
# You can also set it in your :file:`.matplotlibrc` file::
213238
#
214-
# font.sans-serif: Source Han Sans TW, Arial, sans-serif
239+
# font.family: Source Han Sans TW, Arial, sans-serif
215240
#
216241
# To control the font used on per-artist basis use the *name*, *fontname* or
217242
# *fontproperties* keyword arguments documented :doc:`above

0 commit comments

Comments
 (0)