【数学建模之Python】11.炉温曲线可视化
目前正在做高教杯2020年A题,记录一下可视化过程,不断更新
根据制程界限绘图
1.已知某次实验数据(附件中),根据本次实验数据做可视化
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import warnings
warnings.filterwarnings(ignore) # 忽略警告
plt.rc(font, size=16)
plt.rc(font, family=SimHei)
plt.rc(axes, unicode_minus=False)
a = pd.read_excel(附件.xlsx)
T = a.values # 炉温数据
T_up217 = T[np.where(T[:, 1] > 217)[0]] # 大于217摄氏度的数组
T_up217_time = T_up217[-1, 0] - T_up217[0, 0] # 大于217摄氏度的时间
T_max = T[np.where(T[:, 1] == np.max(T[:, 1]))[0], :] # 峰值温度及对应时间
T_between150and190 = T[np.where((T[:, 1] > 150) * (T[:, 1] < 190) * (T[:, 0] < T_max[0, 0]))[0]] # 上升过程中150摄氏度至190摄氏度
plt.figure(某次实验炉温曲线)
plt.plot(T[:, 0], T[:, 1], linestyle=--, linewidth=5, color=dodgerblue, alpha=0.5,
label=完整数据) # alpha=1时完全不透明,alpha=0时完全透明
plt.plot(T_max[:, 0], T_max[:, 1], linewidth=5, color=black, label=峰值)
plt.plot(T_up217[:, 0], T_up217[:, 1], linestyle=-, linewidth=2, color=red, label=大于217摄氏度)
plt.plot(T_between150and190[:, 0], T_between150and190[:, 1], linestyle=-, linewidth=2, color=orange,
label=上升过程中150摄氏度至190摄氏度)
plt.xticks(np.arange(0, 450, 50))
plt.legend() # 显示图例
plt.xlabel(时间/t)
plt.ylabel(温度/℃)
plt.annotate(s="(%s,%s)和(%s,%s)" % (T_max[0, 0], T_max[0, 1], T_max[1, 0], T_max[1, 1]),
xy=(T_max[0, 0], T_max[0, 1]),
xytext=(40, 50),
textcoords=offset points,
arrowprops=dict(headlength=5, width=1, color=black)) # 标注峰值
# 大于217摄氏度的标注
plt.annotate(s="(%s,%s)" % (T_up217[0, 0], T_up217[0, 1]),
xy=(T_up217[0, 0], T_up217[0, 1]),
xytext=(10, -40),
textcoords=offset points,
arrowprops=dict(headlength=5, width=1, color=red)) # 标注左临界值
plt.annotate(s="(%s,%s)" % (T_up217[-1, 0], T_up217[-1, 1]),
xy=(T_up217[-1, 0], T_up217[-1, 1]),
xytext=(50, 0),
textcoords=offset points,
arrowprops=dict(headlength=5, width=1, color=red)) # 标注右临界值
# 上升过程中150~190摄氏度的标注
plt.annotate(s="(%s,%s)" % (T_between150and190[0, 0], T_between150and190[0, 1]),
xy=(T_between150and190[0, 0], T_between150and190[0, 1]),
xytext=(10, -40),
textcoords=offset points,
arrowprops=dict(headlength=5, width=1, color=orange)) # 标注左临界值
plt.annotate(s="(%s,%s)" % (T_between150and190[-1, 0], T_between150and190[-1, 1]),
xy=(T_between150and190[-1, 0], T_between150and190[-1, 1]),
xytext=(10, -40),
textcoords=offset points,
arrowprops=dict(headlength=5, width=1, color=orange)) # 标注右临界值
plt.show()
