1 绘制曲线图
import matplotlib.pyplot as plt # 为方便简介为plt
import numpy as np # 画图过程中会使用numpy
import pandas as pd # 画图过程中会使用pandas
def PythonPlot(x: list, y: list):
#绘制曲线图
plt.rcParams['font.family'] = ['SimHei'] #确保图中中文字体正确显示
plt.rcParams['axes.unicode_minus'] = False #确保负号正确显示
fig = plt.figure() #先创建一个窗口
plt.plot(x, y, color = 'blue', marker = 'o') #plot()画出曲线,并设置曲线颜色,线标记
plt.legend(labels = ['二次曲线图'], loc = 'best') #best表示自动分配最佳位置
plt.xlabel('x轴')
plt.ylabel('y轴')
plt.title('曲线图')
plt.grid()
plt.show() #显示图像
x = np.arange(-1,5,0.01)
y = [a * a - 4 * a + 3 for a in x]
PythonPlot(x, y)
结果为,