{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Using ttf font files\n\nAlthough it is usually not a good idea to explicitly point to a single ttf file\nfor a font instance, you can do so by passing a `pathlib.Path` instance as the\n*font* parameter. Note that passing paths as `str`\\s is intentionally not\nsupported, but you can simply wrap `str`\\s in `pathlib.Path`\\s as needed.\n\nHere, we use the Computer Modern roman font (``cmr10``) shipped with\nMatplotlib.\n\nFor a more flexible solution, see\n:doc:`/gallery/text_labels_and_annotations/font_family_rc` and\n:doc:`/gallery/text_labels_and_annotations/fonts_demo`.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"from pathlib import Path\n\nimport matplotlib.pyplot as plt\n\nimport matplotlib as mpl\n\nfig, ax = plt.subplots()\n\nfpath = Path(mpl.get_data_path(), \"fonts/ttf/cmr10.ttf\")\nax.set_title(f'This is a special font: {fpath.name}', font=fpath)\nax.set_xlabel('This is the default font')\n\nplt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
".. admonition:: References\n\n The use of the following functions, methods, classes and modules is shown\n in this example:\n\n - `matplotlib.axes.Axes.set_title`\n\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.13.2"
}
},
"nbformat": 4,
"nbformat_minor": 0
}