English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Matplotlib has extensive text support, including support for mathematical expressions, TrueType support for raster and vector output, newline characters separated by arbitrary rotation text, and unicode support. Matplotlib includes its own matplotlib.font_manager, which implements a cross-platform, W3C standard font search algorithm.
Users can make extensive controls over text properties (font size, font weight, text position and color, etc.). Matplotlib implements a large number of TeX mathematical symbols and commands.
text - Add text at any position in the Axes. annotate - Add annotations at any position in the Axes using optional arrows. xlabel - Add a label to the x-axis of the Axes. ylabel - Add a label to the y-axis of the Axes. title - Add a title to the Axes. figtext - Add text at any position in the figure. suptitle - Add a title to the figure.
The following command list is used to create text in the Pyplot interface -
# Filename : example.py # Copyright : 2020 By w3codebox # Author by: www.oldtoolbag.com # Date : 2020-08-08 #! /usr/bin/env python #coding=utf-8-8 import matplotlib.pyplot as plt import numpy as np import math import seaborn as sns plt.rcParams['font.sans-serif'] = ['SimHei'] # Step one (replace sans-serif font) plt.rcParams['axes.unicode_minus'] = False # Original source from [Lidi Huo], please contact the author for commercial use, and retain the original link for non-commercial use: fig = plt.figure() ax = fig.add_axes([0,0,1,1]) ax.set_title('axes title') ax.set_xlabel('xlabel') ax.set_ylabel('ylabel') ax.text(3, 8, 'Italic text wrapped in data coordinates', style='italic', bbox = {'facecolor': 'red'} ax.text(2, 6, r'An equation: $E = mc^2')2, fontsize = 15) ax.text(4, 0.05, 'axis color text in axis coords', verticalalignment = 'bottom', color = 'green', fontsize = 15) ax.plot([2], [1], 'o') ax.annotate('annotate', xy = (2, 1), xytext = (3, 4) arrowprops = dict(facecolor = 'black', shrink = 0.05)) ax.axis([0, 10, 0, 10]) plt.show() , fontsize = 15) ax.text(4, 0.05, 'axis color text in axis coords', verticalalignment = 'bottom', color = 'green', fontsize = 15) ax.plot([2], [1], 'o') ax.annotate('annotate', xy = (2, 1), xytext = (3, 4) arrowprops = dict(facecolor = 'black', shrink = 0.05)) ax.axis([0, 10, 0, 10]) plt.show()
Run the above example code to get the following result -