Import your data
Country | Continent | GDP_per_capita | life_expectancy | Population | |
---|---|---|---|---|---|
0 | Afghanistan | Asia | 663 | 54.863 | 22856302 |
1 | Albania | Europe | 4195 | 74.200 | 3071856 |
2 | Algeria | Africa | 5098 | 68.963 | 30533827 |
3 | Angola | Africa | 2446 | 45.234 | 13926373 |
4 | Antigua and Barbuda | N. America | 12738 | 73.544 | 77656 |
Change the font just for the title or axis labels
The default font is BitstreamVeraSans Roman, but we want to try out
something else. You can pass fontname
to .set_xlabel
, .set_ylabel
,
.set_title
, or .annotate
to specify a particular font. This does not
change the font for the numbers on the axes.
Text(0.5,1,'Oceania has small countries')
Change the font for the tick marks/numbers on the axes
Changing the fonts for the labels on each axis (the numbers) is a little bit more complicated, but you can use it in combination with the content above to specify fonts for every part of your graph.
Specify a default font for everything on your graphs
You can also specify a default font for everything in matplotlib
. This will
affect every single plot you make.
Note: Although you can do this, unless you’re practicing to make a house style I recommend specifying single-use fonts (the above section) instead of defaults.
I don’t know why, but you can only set it once. If you change your mind about what you want your default font to be you’ll have to restart your kernel.
It also knows whether your font is serif or sans-serif. If you try it with
serif
and it doesn’t work, change both of them to sans-serif
instead. For
example, if I changed my font to Georgia down below I’d need it to be
serif
instead, since it’s a font with serifs.
Text(0.5,1,'Oceania has small countries')
Listing all of the fonts matplotlib knows about
If you’d like to know what fonts are available for use, check out list all fonts available in matplotlib plus samples.