matplotlib
font listing¶matplotlib
has font_manager to manage fonts across platforms. This notebook checks current font settings and available fonts on the system.
import matplotlib as mpl
import matplotlib.font_manager as fm
import pandas as pd
Show current font settings via rcParams.
for k in filter(lambda k: k.startswith('font'), sorted(mpl.rcParams)):
print('-', k, ':', mpl.rcParams.get(k))
- font.cursive : ['Apple Chancery', 'Textile', 'Zapf Chancery', 'Sand', 'cursive'] - font.family : ['sans-serif'] - font.fantasy : ['Comic Sans MS', 'Chicago', 'Charcoal', 'ImpactWestern', 'fantasy'] - font.monospace : ['Bitstream Vera Sans Mono', 'DejaVu Sans Mono', 'Andale Mono', 'Nimbus Mono L', 'Courier New', 'Courier', 'Fixed', 'Terminal', 'monospace'] - font.sans-serif : ['Bitstream Vera Sans', 'DejaVu Sans', 'Lucida Grande', 'Verdana', 'Geneva', 'Lucid', 'Arial', 'Helvetica', 'Avant Garde', 'sans-serif'] - font.serif : ['Bitstream Vera Serif', 'DejaVu Serif', 'New Century Schoolbook', 'Century Schoolbook L', 'Utopia', 'ITC Bookman', 'Bookman', 'Nimbus Roman No9 L', 'Times New Roman', 'Times', 'Palatino', 'Charter', 'serif'] - font.size : 12.0 - font.stretch : normal - font.style : normal - font.variant : normal - font.weight : normal
Show available fonts in this system. findSystemFonts() returns list of paths of font files.
fonts = fm.findSystemFonts()
len(fonts)
247
FontProperties
provides access methods from given font file.
For pretty printing, pack the values on dataframe.
l = []
for f in fonts:
font = fm.FontProperties(fname=f)
l.append((f, font.get_name(), font.get_family()))
df = pd.DataFrame(l, columns=['path', 'name', 'family'])
df
path | name | family | |
---|---|---|---|
0 | /usr/share/fonts/opentype/font-awesome/FontAwe... | FontAwesome | [sans-serif] |
1 | /usr/share/fonts/truetype/droid/DroidSansArabi... | Droid Sans Arabic | [sans-serif] |
2 | /usr/share/fonts/truetype/adf/AccanthisADFStdN... | Accanthis ADF Std No2 | [sans-serif] |
3 | /usr/share/fonts/opentype/stix-word/STIX-BoldI... | STIX | [sans-serif] |
4 | /usr/share/fonts/opentype/freefont/FreeSansBol... | FreeSans | [sans-serif] |
5 | /usr/share/fonts/truetype/solomos/GFSSolomos.otf | GFS Solomos | [sans-serif] |
6 | /usr/share/fonts/truetype/ebgaramond/EBGaramon... | EB Garamond Initials Fill2 | [sans-serif] |
7 | /usr/share/fonts/opentype/stix/STIXSizeFourSym... | STIXSizeFourSym | [sans-serif] |
8 | /usr/share/fonts/opentype/linux-libertine/LinL... | Linux Libertine O | [sans-serif] |
9 | /usr/share/fonts/opentype/stix/STIXIntegralsUp... | STIXIntegralsUpSm | [sans-serif] |
10 | /usr/share/fonts/truetype/adf/GilliusADF-Itali... | Gillius ADF | [sans-serif] |
11 | /usr/share/fonts/truetype/droid/DroidSansHebre... | Droid Sans Hebrew | [sans-serif] |
12 | /usr/share/fonts/truetype/freefont/FreeMonoBol... | FreeMono | [sans-serif] |
13 | /usr/share/fonts/opentype/stix/STIXGeneral-Bol... | STIXGeneral | [sans-serif] |
14 | /usr/share/fonts/opentype/lobstertwo/LobsterTw... | Lobster Two | [sans-serif] |
15 | /usr/share/fonts/opentype/linux-libertine/LinB... | Linux Biolinum Keyboard O | [sans-serif] |
16 | /usr/share/fonts/truetype/droid/DroidSansJapan... | Droid Sans Japanese | [sans-serif] |
17 | /usr/share/fonts/truetype/dejavu/DejaVuSans-Ex... | DejaVu Sans | [sans-serif] |
18 | /usr/share/fonts/opentype/freefont/FreeSans.otf | FreeSans | [sans-serif] |
19 | /usr/share/fonts/opentype/cabin/Cabin-Regular.otf | Cabin | [sans-serif] |
20 | /usr/share/fonts/truetype/dejavu/DejaVuSerifCo... | DejaVu Serif | [sans-serif] |
21 | /usr/share/fonts/truetype/lato/Lato-SemiboldIt... | Lato | [sans-serif] |
22 | /usr/share/fonts/truetype/crosextra/Carlito-Bo... | Carlito | [sans-serif] |
23 | /usr/share/fonts/truetype/droid/DroidKufi-Bold... | Droid Arabic Kufi | [sans-serif] |
24 | /usr/share/fonts/truetype/asana-math/Asana-Mat... | Asana Math | [sans-serif] |
25 | /usr/share/fonts/truetype/droid/DroidSans.ttf | Droid Sans | [sans-serif] |
26 | /usr/share/fonts/truetype/droid/DroidNaskh-Reg... | Droid Arabic Naskh | [sans-serif] |
27 | /usr/share/fonts/truetype/lato/Lato-HeavyItali... | Lato | [sans-serif] |
28 | /usr/share/fonts/truetype/adf/GilliusADFNo2Cd-... | Gillius ADF No2 Cd | [sans-serif] |
29 | /usr/share/fonts/truetype/neohellenic/GFSNeohe... | GFS Neohellenic | [sans-serif] |
... | ... | ... | ... |
217 | /usr/share/fonts/opentype/cabin/Cabin-SemiBold... | Cabin | [sans-serif] |
218 | /usr/share/fonts/truetype/gentium-basic/GenBas... | Gentium Basic | [sans-serif] |
219 | /usr/share/fonts/truetype/inconsolata/Inconsol... | Inconsolata | [sans-serif] |
220 | /usr/share/fonts/truetype/crosextra/Carlito-It... | Carlito | [sans-serif] |
221 | /usr/share/fonts/opentype/freefont/FreeSerif.otf | FreeSerif | [sans-serif] |
222 | /usr/share/fonts/truetype/dejavu/DejaVuSerif-B... | DejaVu Serif | [sans-serif] |
223 | /usr/share/fonts/truetype/complutum/GFSPolyglo... | GFS Complutum | [sans-serif] |
224 | /usr/share/fonts/truetype/adf/UniversalisADFCd... | Universalis ADF Cd Std | [sans-serif] |
225 | /usr/share/fonts/opentype/linux-libertine/LinL... | Linux Libertine Mono O | [sans-serif] |
226 | /usr/share/fonts/truetype/ebgaramond/EBGaramon... | EB Garamond | [sans-serif] |
227 | /usr/share/fonts/opentype/stix/STIXIntegralsUp... | STIXIntegralsUpD | [sans-serif] |
228 | /usr/share/fonts/truetype/dejavu/DejaVuSans-Bo... | DejaVu Sans | [sans-serif] |
229 | /usr/share/fonts/truetype/freefont/FreeSansBol... | FreeSans | [sans-serif] |
230 | /usr/share/fonts/truetype/droid/DroidSerif-Bol... | Droid Serif | [sans-serif] |
231 | /usr/share/fonts/opentype/cabin/Cabin-Medium.otf | Cabin | [sans-serif] |
232 | /usr/share/fonts/opentype/stix/STIXIntegralsSm... | STIXIntegralsSm | [sans-serif] |
233 | /usr/share/fonts/opentype/linux-libertine/LinL... | Linux Libertine Display O | [sans-serif] |
234 | /usr/share/fonts/truetype/migmix-1p-20150712/m... | MigMix 1P | [sans-serif] |
235 | /usr/share/fonts/opentype/stix/STIXIntegralsUp... | STIXIntegralsUp | [sans-serif] |
236 | /usr/share/fonts/truetype/IPAfont00303/ipag.ttf | IPAGothic | [sans-serif] |
237 | /usr/share/fonts/truetype/artemisia/GFSArtemis... | GFS Artemisia | [sans-serif] |
238 | /usr/share/fonts/truetype/ebgaramond/EBGaramon... | EB Garamond | [sans-serif] |
239 | /usr/share/fonts/truetype/lato/Lato-BlackItali... | Lato | [sans-serif] |
240 | /usr/share/fonts/opentype/stix/STIXSizeThreeSy... | STIXSizeThreeSym | [sans-serif] |
241 | /usr/share/fonts/opentype/freefont/FreeSerifIt... | FreeSerif | [sans-serif] |
242 | /usr/share/fonts/opentype/stix/STIXSizeFiveSym... | STIXSizeFiveSym | [sans-serif] |
243 | /usr/share/fonts/opentype/lobstertwo/LobsterTw... | Lobster Two | [sans-serif] |
244 | /usr/share/fonts/truetype/crosextra/Caladea-Re... | Caladea | [sans-serif] |
245 | /usr/share/fonts/opentype/stix/STIXSizeTwoSym-... | STIXSizeTwoSym | [sans-serif] |
246 | /usr/share/fonts/opentype/ebgaramond/EBGaramon... | EB Garamond | [sans-serif] |
247 rows × 3 columns
Filter truetype fonts.
df[df['path'].apply(lambda s: 'truetype' in s)]
path | name | family | |
---|---|---|---|
1 | /usr/share/fonts/truetype/droid/DroidSansArabi... | Droid Sans Arabic | [sans-serif] |
2 | /usr/share/fonts/truetype/adf/AccanthisADFStdN... | Accanthis ADF Std No2 | [sans-serif] |
5 | /usr/share/fonts/truetype/solomos/GFSSolomos.otf | GFS Solomos | [sans-serif] |
6 | /usr/share/fonts/truetype/ebgaramond/EBGaramon... | EB Garamond Initials Fill2 | [sans-serif] |
10 | /usr/share/fonts/truetype/adf/GilliusADF-Itali... | Gillius ADF | [sans-serif] |
11 | /usr/share/fonts/truetype/droid/DroidSansHebre... | Droid Sans Hebrew | [sans-serif] |
12 | /usr/share/fonts/truetype/freefont/FreeMonoBol... | FreeMono | [sans-serif] |
16 | /usr/share/fonts/truetype/droid/DroidSansJapan... | Droid Sans Japanese | [sans-serif] |
17 | /usr/share/fonts/truetype/dejavu/DejaVuSans-Ex... | DejaVu Sans | [sans-serif] |
20 | /usr/share/fonts/truetype/dejavu/DejaVuSerifCo... | DejaVu Serif | [sans-serif] |
21 | /usr/share/fonts/truetype/lato/Lato-SemiboldIt... | Lato | [sans-serif] |
22 | /usr/share/fonts/truetype/crosextra/Carlito-Bo... | Carlito | [sans-serif] |
23 | /usr/share/fonts/truetype/droid/DroidKufi-Bold... | Droid Arabic Kufi | [sans-serif] |
24 | /usr/share/fonts/truetype/asana-math/Asana-Mat... | Asana Math | [sans-serif] |
25 | /usr/share/fonts/truetype/droid/DroidSans.ttf | Droid Sans | [sans-serif] |
26 | /usr/share/fonts/truetype/droid/DroidNaskh-Reg... | Droid Arabic Naskh | [sans-serif] |
27 | /usr/share/fonts/truetype/lato/Lato-HeavyItali... | Lato | [sans-serif] |
28 | /usr/share/fonts/truetype/adf/GilliusADFNo2Cd-... | Gillius ADF No2 Cd | [sans-serif] |
29 | /usr/share/fonts/truetype/neohellenic/GFSNeohe... | GFS Neohellenic | [sans-serif] |
30 | /usr/share/fonts/truetype/droid/DroidSansHebre... | Droid Sans Hebrew | [sans-serif] |
31 | /usr/share/fonts/truetype/artemisia/GFSArtemis... | GFS Didot | [sans-serif] |
33 | /usr/share/fonts/truetype/adf/AccanthisADFStdN... | Accanthis ADF Std No3 | [sans-serif] |
34 | /usr/share/fonts/truetype/lato/Lato-Hairline.ttf | Lato | [sans-serif] |
37 | /usr/share/fonts/truetype/lato/Lato-Italic.ttf | Lato | [sans-serif] |
38 | /usr/share/fonts/truetype/dejavu/DejaVuSansCon... | DejaVu Sans | [sans-serif] |
41 | /usr/share/fonts/truetype/lato/Lato-Thin.ttf | Lato | [sans-serif] |
42 | /usr/share/fonts/truetype/junicode/Junicode-Bo... | Junicode | [sans-serif] |
44 | /usr/share/fonts/truetype/comfortaa/Comfortaa-... | Comfortaa | [sans-serif] |
47 | /usr/share/fonts/truetype/adf/GilliusADFCd-Reg... | Gillius ADF Cd | [sans-serif] |
48 | /usr/share/fonts/truetype/junicode/Junicode-It... | Junicode | [sans-serif] |
... | ... | ... | ... |
201 | /usr/share/fonts/truetype/crosextra/Caladea-It... | Caladea | [sans-serif] |
202 | /usr/share/fonts/truetype/dejavu/DejaVuSerifCo... | DejaVu Serif | [sans-serif] |
203 | /usr/share/fonts/truetype/adf/GilliusADFNo2Cd-... | Gillius ADF No2 Cd | [sans-serif] |
205 | /usr/share/fonts/truetype/freefont/FreeSerifBo... | FreeSerif | [sans-serif] |
206 | /usr/share/fonts/truetype/olga/GFSOlga.otf | GFS Olga | [sans-serif] |
207 | /usr/share/fonts/truetype/lato/Lato-Bold.ttf | Lato | [sans-serif] |
208 | /usr/share/fonts/truetype/adf/UniversalisADFCd... | Universalis ADF Cd Std | [sans-serif] |
209 | /usr/share/fonts/truetype/adf/GilliusADFCd-Bol... | Gillius ADF Cd | [sans-serif] |
210 | /usr/share/fonts/truetype/freefont/FreeSerifBo... | FreeSerif | [sans-serif] |
211 | /usr/share/fonts/truetype/adf/AccanthisADFStd-... | Accanthis ADF Std | [sans-serif] |
212 | /usr/share/fonts/truetype/crosextra/Caladea-Bo... | Caladea | [sans-serif] |
213 | /usr/share/fonts/truetype/droid/DroidSansMono.ttf | Droid Sans Mono | [sans-serif] |
214 | /usr/share/fonts/truetype/lato/Lato-Regular.ttf | Lato | [sans-serif] |
215 | /usr/share/fonts/truetype/droid/DroidNaskhUI-R... | Droid Naskh Shift Alt | [sans-serif] |
218 | /usr/share/fonts/truetype/gentium-basic/GenBas... | Gentium Basic | [sans-serif] |
219 | /usr/share/fonts/truetype/inconsolata/Inconsol... | Inconsolata | [sans-serif] |
220 | /usr/share/fonts/truetype/crosextra/Carlito-It... | Carlito | [sans-serif] |
222 | /usr/share/fonts/truetype/dejavu/DejaVuSerif-B... | DejaVu Serif | [sans-serif] |
223 | /usr/share/fonts/truetype/complutum/GFSPolyglo... | GFS Complutum | [sans-serif] |
224 | /usr/share/fonts/truetype/adf/UniversalisADFCd... | Universalis ADF Cd Std | [sans-serif] |
226 | /usr/share/fonts/truetype/ebgaramond/EBGaramon... | EB Garamond | [sans-serif] |
228 | /usr/share/fonts/truetype/dejavu/DejaVuSans-Bo... | DejaVu Sans | [sans-serif] |
229 | /usr/share/fonts/truetype/freefont/FreeSansBol... | FreeSans | [sans-serif] |
230 | /usr/share/fonts/truetype/droid/DroidSerif-Bol... | Droid Serif | [sans-serif] |
234 | /usr/share/fonts/truetype/migmix-1p-20150712/m... | MigMix 1P | [sans-serif] |
236 | /usr/share/fonts/truetype/IPAfont00303/ipag.ttf | IPAGothic | [sans-serif] |
237 | /usr/share/fonts/truetype/artemisia/GFSArtemis... | GFS Artemisia | [sans-serif] |
238 | /usr/share/fonts/truetype/ebgaramond/EBGaramon... | EB Garamond | [sans-serif] |
239 | /usr/share/fonts/truetype/lato/Lato-BlackItali... | Lato | [sans-serif] |
244 | /usr/share/fonts/truetype/crosextra/Caladea-Re... | Caladea | [sans-serif] |
167 rows × 3 columns
Filter IPA fonts after putting IPA Font files under /usr/share/fonts/truetype
.
$ docker exec notebook cp -r /dataset/IPAfont00303 /usr/share/fonts/truetype
df[df['path'].apply(lambda s: 'IPA' in s)]
path | name | family | |
---|---|---|---|
82 | /usr/share/fonts/truetype/IPAfont00303/ipagp.ttf | IPAPGothic | [sans-serif] |
108 | /usr/share/fonts/truetype/IPAfont00303/ipamp.ttf | IPAPMincho | [sans-serif] |
138 | /usr/share/fonts/truetype/IPAfont00303/ipam.ttf | IPAMincho | [sans-serif] |
236 | /usr/share/fonts/truetype/IPAfont00303/ipag.ttf | IPAGothic | [sans-serif] |
matplotlib.pyplot
¶%matplotlib inline
import matplotlib.pyplot as plt
Default font family does not handle Japanese font.
plt.plot([1,2,3,4])
plt.ylabel('数値')
plt.show()
Changing font.family setting enables Japanese font if available in the system. Be sure to set fontdict when calling ylabel() method.
plt.plot([1,2,3,4])
plt.ylabel('数値', fontdict={'family': 'IPAPGothic'})
plt.show()
seaborn
¶import seaborn as sns
data = pd.DataFrame([1, 2, 3, 4], columns=['数値'])
sns.jointplot(x='数値', y='数値', data=data, xlim=(0, 5), ylim=(0, 5))
<seaborn.axisgrid.JointGrid at 0x7f1b17116a58>
Enable Japanese font setting to call set() method, which affects various configuration globally.
sns.set(font=['IPAPGothic', 'IPAGothic'])
sns.jointplot(x='数値', y='数値', data=data, xlim=(0, 5), ylim=(0, 5))
<seaborn.axisgrid.JointGrid at 0x7f1b1692d978>
Here is the list of current axes styles.
sns.axes_style()
{'axes.axisbelow': True, 'axes.edgecolor': 'white', 'axes.facecolor': '#EAEAF2', 'axes.grid': True, 'axes.labelcolor': '.15', 'axes.linewidth': 0.0, 'figure.facecolor': 'white', 'font.family': ['IPAPGothic', 'IPAGothic'], 'font.sans-serif': ['Arial', 'Liberation Sans', 'Bitstream Vera Sans', 'sans-serif'], 'grid.color': 'white', 'grid.linestyle': '-', 'image.cmap': 'Greys', 'legend.frameon': False, 'legend.numpoints': 1, 'legend.scatterpoints': 1, 'lines.solid_capstyle': 'round', 'text.color': '.15', 'xtick.color': '.15', 'xtick.direction': 'out', 'xtick.major.size': 0.0, 'xtick.minor.size': 0.0, 'ytick.color': '.15', 'ytick.direction': 'out', 'ytick.major.size': 0.0, 'ytick.minor.size': 0.0}
Once enable Seaborn, matplotlib default settings was affected, not only fonts but also style including background color.
plt.plot([1,2,3,4])
plt.ylabel('数値')
plt.show()
In other words, super easy confugration is calling set()
via Seaborn.