01-设置全局字体+大小
02-绘制多条直线03-折线图-蓝色点+红色线+坐标
01-设置全局字体+大小
import matplotlib.pyplot as pltimport matplotlib # 载入matplotlib完整库matplotlib.rcParams['font.family'] = 'Microsoft Yahei' # 字体,改为微软雅黑,默认 sans-serifmatplotlib.rcParams['font.size'] = 32 # 字体大小,整数字号,默认10a = range(10)x = ay = aplt.plot(x, y) # 折线图plt.grid() # 设置网格plt.show() # 显示图形
02-绘制多条直线
import matplotlib.pyplot as pltimport numpy as npimport matplotlib # 载入matplotlib完整库matplotlib.rcParams['font.family'] = 'Microsoft Yahei' # 字体,改为微软雅黑,默认 sans-serifmatplotlib.rcParams['font.size'] = 32 # 字体大小,整数字号,默认10a = np.arange(10)plt.figure(figsize=(20, 20), dpi=80)# 方法一:# plt.plot(a, a, a, a * 1.5, a, a * 3) # 折线图# 方法二:plt.plot(a, a) # 折线图plt.plot(a, a * 1.5) # 折线图plt.plot(a, a * 3) # 折线图plt.grid() # 设置网格plt.show() # 显示图形
03-折线图-蓝色点+红色线+坐标
import matplotlib.pyplot as pltimport numpy as npimport matplotlib # 载入matplotlib完整库matplotlib.rcParams['font.family'] = 'Microsoft Yahei' # 字体,改为微软雅黑,默认 sans-serif# matplotlib.rcParams['font.size'] = 32 # 字体大小,整数字号,默认10a = np.arange(10)# y = x ** 2x = ay = list(map(lambda i: i ** 2, a))plt.figure(figsize=(20, 20), dpi=80)plt.plot(x, y, color='r', markerfacecolor='blue', marker='o')for i, j in zip(x, y): plt.text(i + 0.3, j - 6, (i, j), ha='center', va='bottom', fontsize=30) # 标记文本plt.legend(apha=0.1)plt.grid() # 设置网格plt.show() # 显示图形