网络编程
位置:首页>> 网络编程>> Python编程>> python 离散点图画法的实现

python 离散点图画法的实现

作者:心之所向521  发布时间:2021-04-14 17:00:31 

标签:python,离散点图

基础代码

pred_y = test_output.data.numpy()
pred_y = pred_y.flatten()
print(pred_y, 'prediction number')
print(test_y[:355].numpy(), 'real number')

import matplotlib.pyplot as plt
plt.rc("font", family='KaiTi')
plt.figure()
f, axes = plt.subplots(1, 1)
x = np.arange(1, 356)
# axes.plot(x , pred_y)
axes.scatter(x,pred_y, c='r', marker = 'o')
plt.axhline(36.7, c ='g')
axes.set_xlabel("位置点位")
axes.set_ylabel("预测值")
axes.set_title("矫正网络结果")
plt.savefig("result.png")
plt.show()

python 离散点图画法的实现

离散图画法如上所示。

改进

python 离散点图画法的实现

import matplotlib.pyplot as plt
plt.rc("font", family='KaiTi')
plt.figure()
f, axes = plt.subplots(1, 1)
x = np.arange(1, 356)
# axes.plot(x , pred_y)
axes.scatter(x, pred_y, c='r', marker = 'o')
plt.axhline(36.7, c ='g')
axes.set_xlabel("位置点位")
axes.set_ylabel("预测值")
axes.set_title("矫正网络预测结果")
axes.set_ylim((36, 37))
plt.savefig("result.png")
plt.show()

再次改进:

python 离散点图画法的实现

import matplotlib.pyplot as plt
plt.rc("font", family='KaiTi')
plt.figure()
f, axes = plt.subplots(1, 1)
x = np.arange(1, 356)
# axes.plot(x , pred_y)
axes.scatter(x, pred_y, c='r', marker = 'o')
plt.axhline(36.7, c ='g')
axes.set_xlabel("位置点位")
axes.set_ylabel("预测值")
axes.set_title("矫正网络预测结果")
axes.set_ylim((36, 37))
plt.savefig("result.png")
plt.legend(['real', 'predict'], loc='upper left')
plt.show()

又次改进:

python 离散点图画法的实现

import matplotlib.pyplot as plt
plt.rc("font", family='KaiTi')
plt.figure()
f, axes = plt.subplots(1, 1)
x = np.arange(1, 356)
# axes.plot(x , pred_y)
axes.scatter(x, pred_y, c='r', s=3, marker = 'o')
plt.axhline(36.7, c ='g')
axes.set_xlabel("位置点位")
axes.set_ylabel("预测值")
axes.set_title("矫正网络预测结果")
axes.set_ylim((36, 37))
plt.savefig("result.png")
plt.legend(['真实值36.7℃', '预测值'], loc='upper left')
plt.show()

改进:----加准确率

python 离散点图画法的实现

import matplotlib.pyplot as plt
plt.rc("font", family='KaiTi')
plt.figure()
f, axes = plt.subplots(1, 1)
x = np.arange(1, 356)
# axes.plot(x , pred_y)
axes.scatter(x, pred_y, c='r', s=3, marker = 'o')
plt.axhline(36.7, c ='g')
axes.set_xlabel("位置点位")
axes.set_ylabel("预测值")
axes.set_title("矫正网络预测结果")
axes.set_ylim((36, 37))
plt.savefig("result.png")
plt.legend(['真实值36.7℃', '预测值'], loc='upper left')

row_labels = ['准确率:']
col_labels = ['数值']
table_vals = [['{:.2f}%'.format(v*100)]]
row_colors = ['gold']
my_table = plt.table(cellText=table_vals, colWidths=[0.1] * 5,
                            rowLabels=row_labels, rowColours=row_colors, loc='best')
plt.show()

来源:https://blog.csdn.net/weixin_45564943/article/details/123880105

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com