# 画模型参数散点图

2021-04-10 17:33:12  阅读：21  来源： 互联网

``````import matplotlib.pyplot as plt
import numpy as np

fig, axs = plt.subplots(nrows=2, ncols=2, figsize=(6, 6))

s1 = 0
s2 = 0
s3 = 0
s4 = 0
#定义4个变量，用来求和然后求平均值

for i in range(0, 9):
s1 += float(parameters[i][1])
s2 += float(parameters[i][2])
s3 += float(parameters[i][3])
s4 += float(parameters[i][4])
#累加求和

para1 = float(parameters[i][1])
para2 = float(parameters[i][2])
para3 = float(parameters[i][3])
para4 = float(parameters[i][4])
#读取参数值

axs[0, 0].plot(i, para1, color='C0',marker = 'D')
axs[0, 1].plot(i, para2, color='C1',marker = 'D')
axs[1, 0].plot(i, para3, color='C2',marker = 'D')
axs[1, 1].plot(i, para4, color='C3',marker = 'D')
#画参数值点

m1 = s1/9.
m2 = s2/9.
m3 = s3/9.
m4 = s4/9.
#求平均值

axs[0, 0].axhline(m1,color='C0')       #画均值线
axs[0, 0].set_ylabel("parameter1")       #图例
#axs[0, 0].set_ylim(m1*0.5, m1*1.5)
axs[0, 0].grid(True)       #画网格线

axs[0, 1].axhline(m2,color='C1')
axs[0, 1].set_ylabel("parameter2")
#axs[0, 1].set_ylim(m2*0.5, m2*1.5)
axs[0, 1].grid(True)

axs[1, 0].axhline(m3,color='C2')
axs[1, 0].set_ylabel("parameter3")
#axs[1, 0].set_ylim(m3*0.5, m3*1.5)
axs[1, 0].grid(True)

axs[1, 1].axhline(m4,color='C3')
axs[1, 1].set_ylabel("parameter4")
axs[1, 1].set_ylim(m4*0.5, m4*1.5)#设置上下限
axs[1, 1].grid(True)

fig.suptitle('model')    #标题
plt.show()
``````