matplotlib三线对比:
import matplotlib.pyplot as plt
base = [1, 2, 3, 4]
x1 = [0.15, 0.08, 0.04, 0.04]
y1 = [0.91, 0.95, 0.97, 0.91]
x2 = [0.15, 0.08, 0.04, 0.09]
y2 = [0.91, 0.94, 0.97, 0.88]
x3 = [0.08, 0.08, 0.08, 0.08]
y3 = [0.95, 0.95, 0.95, 0.95]
plt.subplot(1, 2, 1) # 子绘图1
plt.rcParams['font.sans-serif'] = ['Times New Roman'] # 设置字体
plt.xlabel('Level') # x轴标题
plt.ylabel('Mean Accuracy') # y轴标题
plt.plot(base, y1, marker='o', markersize=3, linestyle='--') # 绘制折线图,添加数据点,设置点的大小
plt.plot(base, y2, marker='*', markersize=3, linestyle='-.')
plt.plot(base, y3, marker='s', markersize=3, linestyle='-')
plt.legend(['Algorithm 1', 'Algorithm 2', 'Algorithm 3']) # 设置折线名称
plt.subplot(1, 2, 2) # 子绘图2
plt.rcParams['font.sans-serif'] = ['Times New Roman'] # 设置字体
plt.xlabel('Level') # x轴标题
plt.ylabel('Standard Deviation') # y轴标题
plt.plot(base, x1, marker='o', markersize=3, linestyle='--') # 绘制折线图,添加数据点,设置点的大小
plt.plot(base, x2, marker='*', markersize=3, linestyle='-.')
plt.plot(base, x3, marker='s', markersize=3, linestyle='-')
plt.legend(['Algorithm 1', 'Algorithm 2', 'Algorithm 3']) # 设置折线名称
plt.suptitle("Performance Comparison")
plt.show() # 显示折线图
运行结果:
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)