FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
matplotlib.github.com/1.4.1/examples/api/font_file.py at main · matplotlib/matplotlib.github.com · GitHub
matplotlib
/
matplotlib.github.com
Public
Notifications
You must be signed in to change notification settings
Fork
62
Star
29
Code
Issues
1
Pull requests
2
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
matplotlib.github.com
/
1.4.1
/
examples
/
api
/
font_file.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
39 lines (33 loc) · 1.15 KB
Breadcrumbs
matplotlib.github.com
/
1.4.1
/
examples
/
api
/
font_file.py
Copy path
File metadata and controls
39 lines (33 loc) · 1.15 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# -*- noplot -*-
"""
Although it is usually not a good idea to explicitly point to a single
ttf file for a font instance, you can do so using the
font_manager.FontProperties fname argument (for a more flexible
solution, see the font_fmaily_rc.py and fonts_demo.py examples).
"""
import
sys
import
os
import
matplotlib
.
font_manager
as
fm
import
matplotlib
.
pyplot
as
plt
fig
,
ax
=
plt
.
subplots
()
ax
.
plot
([
1
,
2
,
3
])
if
sys
.
platform
==
'win32'
:
fpath
=
'C:
\\
Windows
\\
Fonts
\\
Tahoma.ttf'
elif
sys
.
platform
.
startswith
(
'linux'
):
fonts
=
[
'/usr/share/fonts/truetype/freefont/FreeSansBoldOblique.ttf'
,
'/usr/share/fonts/truetype/ttf-liberation/LiberationSans-BoldItalic.ttf'
,
'/usr/share/fonts/truetype/msttcorefonts/Comic_Sans_MS.ttf'
,
]
for
fpath
in
fonts
:
if
os
.
path
.
exists
(
fpath
):
break
else
:
fpath
=
'/Library/Fonts/Tahoma.ttf'
if
os
.
path
.
exists
(
fpath
):
prop
=
fm
.
FontProperties
(
fname
=
fpath
)
fname
=
os
.
path
.
split
(
fpath
)[
1
]
ax
.
set_title
(
'this is a special font: %s'
%
fname
,
fontproperties
=
prop
)
else
:
ax
.
set_title
(
'Demo fails--cannot find a demo font'
)
ax
.
set_xlabel
(
'This is the default font'
)
plt
.
show
()
Back
|
FazBrowse Home
|
New Git URL