1.设置中文使用matplotlib.font_manager,并重新定义字体font = FontProperties(fname=r"C:\Windows\Fonts\simhei.ttf", size=14)
2.定义坐标轴标签位置plt.text(5, -5, ‘X axis (Year)…’, ha=‘left’, rotation=0, wrap=True)
3.定义坐标轴位置ax.xaxis.set_ticks_position(‘bottom’)
4.定义坐标轴刻度ax.set_xticklabels([‘2017’,‘2018’,’ ‘,‘2020’,‘2021’],rotation=45,fontsize=‘small’)
5.定义图名标题plt.title(u’测试函数’, fontproperties=font,loc=‘left’)
6.定义曲线上主要坐标点plt.annotate("(%s,%s)" % xy, xy=xy, xytext=(-20, 10), textcoords=‘offset points’)
#-- coding: utf-8 –
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.font_manager import FontProperties
font = FontProperties(fname=r"C:\Windows\Fonts\simhei.ttf", size=14)
x = np.linspace(-5, 5, 50)
x1 = np.linspace(-5,5,5)
y1 = 3 * x1-4
y2 = -2*x * x+33
y3 = 3/x
plt.figure()
plt.text(5, -5, ‘X axis (Year)…’, ha=‘left’, rotation=0, wrap=True) #坐标轴标签重新设置
plt.text(-0.5, 30, ‘Y axis…’, ha=‘left’, rotation=90, wrap=