赞
踩
数学模型:一个大气压国际海水状态方程(温度-2~40℃,实用盐度0~42)
讨论在一个“标准大气压”(海压为0)下,海水密度与实用盐度S与温度T的关系
ρ(S,t,0) = ρw+ AS + BS**3/2 +CS**2
python画图,源代码如下:
import matplotlib.pyplot as plt import numpy as np from matplotlib import cm from matplotlib import colors # 导入公式 def A(t): a = 8.24493 * 10 ** -1 - 4.0899 * 10 ** -3 * t + 7.6438 * 10 ** -5 * t ** 2 - 8.2467 * 10 ** -7 * t ** 3 + 5.3875 * 10 ** -9 * t ** 4 return a def B(t): b = -5.72466 * 10 ** -3 + 1.00227 * 10 ** -4 * t - 1.6546 * 10 ** -6 * t ** 2 return b C = 4.8314 * 10 ** -4 def pw(t): p = 999.842594 + 6.793952 * 10 ** -2 * t - 9.095290 * 10 ** -3 * t ** 2 + 1.001685 * 10 ** -4 * t ** 3 - 1.120083 * 10 ** -6 * t ** 4 + 6.536332 * 10 ** -9 * t ** 5 return p # 标准大气压下,海压为0 def density(t=19, S=21): d = pw(t) + A(t) * S + B(t) * S ** (3 / 2) + C * S ** 2 # print('pw={}, A={}, B={}, C={}'.format(pw(t), A(t), B(t), C)) return round(d, 7) # 生成数据 t_values = np.linspace(-2, 40, 43) # 添加颜色映射 cmap = cm.get_cmap('RdYlBu_r', 42) # 数据可视化 fig, ax = plt.subplots(figsize=(8, 6)) plt.style.use('seaborn-notebook') plt.grid(True) plt.title('density with temperature and salty'.title()) for s in np.arange(0, 43, 7): den_t = [] i = int(s / 7) for t_value in t_values: den_t.append(density(t=t_value, S=s)) ax.plot(t_values, den_t, c=cmap(s), label='S={}'.format(s), linewidth=2) ax.legend(shadow=False, fontsize=8) # 设置颜色条 norm = colors.Normalize(vmin=0, vmax=42) cb = plt.colorbar(cm.ScalarMappable(norm=norm, cmap=cmap), ax=ax, label='Salty', ticks=np.arange(0, 43, 7)) # 坐标轴 plt.xlim(-2, 40) plt.xticks(np.arange(-2, 41, 6)) plt.xlabel('Temperature:℃') plt.ylim(995, 1035) plt.yticks(np.arange(995, 1036, 5)) plt.ylabel('Density:kg/m³') plt.show()
结果如图:
第一次发博客,本人水平有限,欢迎指正。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。