Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e8eb3dc

Browse filesBrowse files
dstansbyMeeseeksDev[bot]
authored and
MeeseeksDev[bot]
committed
Backport PR #9689: Updates to font-related examples.
1 parent b8a1284 commit e8eb3dc
Copy full SHA for e8eb3dc

File tree

Expand file treeCollapse file tree

5 files changed

+41
-54
lines changed
Filter options
Expand file treeCollapse file tree

5 files changed

+41
-54
lines changed

‎examples/api/font_family_rc_sgskip.py

Copy file name to clipboardExpand all lines: examples/api/font_family_rc_sgskip.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
style (e.g., 'serif', 'sans-serif', or 'monospace').
88
99
In the example below, we only allow one font family (Tahoma) for the
10-
san-serif font style. You the default family with the font.family rc
10+
sans-serif font style. You the default family with the font.family rc
1111
param, e.g.,::
1212
1313
rcParams['font.family'] = 'sans-serif'

‎examples/api/font_file.py

Copy file name to clipboard
+28Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"""
2+
===================================
3+
Using a ttf font file in Matplotlib
4+
===================================
5+
6+
Although it is usually not a good idea to explicitly point to a single ttf file
7+
for a font instance, you can do so using the `font_manager.FontProperties`
8+
*fname* argument.
9+
10+
Here, we use the Computer Modern roman font (``cmr10``) shipped with
11+
Matplotlib.
12+
13+
For a more flexible solution, see :doc:`/gallery/api/font_family_rc_sgskip` and
14+
:doc:`/gallery/text_labels_and_annotations/fonts_demo`.
15+
"""
16+
17+
import os
18+
from matplotlib import font_manager as fm, pyplot as plt, rcParams
19+
20+
fig, ax = plt.subplots()
21+
22+
fpath = os.path.join(rcParams["datapath"], "fonts/ttf/cmr10.ttf")
23+
prop = fm.FontProperties(fname=fpath)
24+
fname = os.path.split(fpath)[1]
25+
ax.set_title('This is a special font: {}'.format(fname), fontproperties=prop)
26+
ax.set_xlabel('This is the default font')
27+
28+
plt.show()

‎examples/api/font_file_sgskip.py

Copy file name to clipboardExpand all lines: examples/api/font_file_sgskip.py
-42Lines changed: 0 additions & 42 deletions
This file was deleted.

‎examples/text_labels_and_annotations/fonts_demo.py

Copy file name to clipboardExpand all lines: examples/text_labels_and_annotations/fonts_demo.py
+6-6Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
"""
2-
==========
3-
Fonts Demo
4-
==========
2+
==================================
3+
Fonts demo (object-oriented style)
4+
==================================
55
6-
Show how to set custom font properties.
6+
Set font properties using setters.
77
8-
For interactive users, you can also use kwargs to the text command,
9-
which requires less typing. See examples/fonts_demo_kw.py
8+
See :doc:`fonts_demo_kw` to achieve the same effect using kwargs.
109
"""
10+
1111
from matplotlib.font_manager import FontProperties
1212
import matplotlib.pyplot as plt
1313

‎examples/text_labels_and_annotations/fonts_demo_kw.py

Copy file name to clipboardExpand all lines: examples/text_labels_and_annotations/fonts_demo_kw.py
+6-5Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
"""
2-
=============
3-
Fonts Demo Kw
4-
=============
2+
===================
3+
Fonts demo (kwargs)
4+
===================
55
6-
Same as fonts_demo using kwargs. If you prefer a more pythonic, OO
7-
style of coding, see examples/fonts_demo.py.
6+
Set font properties using kwargs.
87
8+
See :doc:`fonts_demo` to achieve the same effect using setters.
99
"""
10+
1011
from matplotlib.font_manager import FontProperties
1112
import matplotlib.pyplot as plt
1213
import numpy as np

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.