- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to load a .ttf file in Matplotlib using mpl.rcParams?
To load a .ttf file in Matplotlib using mpl.rcParams, we can take the following steps −
- Set the figure size and adjust the padding between and around the subplots.
- Initialize the path for the .ttf file.
- Get an instance of a class for storing and manipulating the font properties.
- Set the font family with the name of the font that best matches the font properties.
- Create a figure and a set of subplots.
- Set the title of the figure.
- To display the figure, use show() method.
Example
from matplotlib import pyplot as plt, font_manager as fm plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True path = '/usr/share/fonts/truetype/malayalam/Karumbi.ttf' fprop = fm.FontProperties(fname=path) plt.rcParams['font.family'] = fprop.get_name() fig, ax = plt.subplots() ax.set_title('This is my title!', size=40) plt.show()
Output
Advertisements