有人能帮我用MatPlotLib生成一个2D彩色图吗?我试图绘制一个函数removal_fraction(P_inlet,T_inlet,P_tank),其中P_tank是常数。
下面是我的代码:
def removal_fraction(P_inlet,T_inlet,P_tank):
#Pressure in flash tank is P_tank, in Pa(a)
#Enthalpy of sap before flash tank
H_inlet=cp.PropsSI('H',"P",P_inlet,"T",T_inlet,"water") #J/kg
#Sensible enthalpy of sap once in the tank
H_sensible_tank=cp.PropsSI('H',"P",P_tank,"Q",0,"water") #J/kg
#Heat lost to latent vaporization in the tank
Latent_heat_transferred=H_inlet-H_sensible_tank #J/kg
#Latent enthalpy of vaporization of sap in the tank (J/kg)
H_latent_tank=cp.PropsSI('H',"P",P_tank,"Q",1,"water")-cp.PropsSI('H',"P",P_tank,"Q",0,"water") #J/kg
#Proportion of water evaporated
R_water_evap=Latent_heat_transferred/H_latent_tank #kg water/kg water
return R_water_evap
P_inlet=np.linspace(200000,100000*40,500) #Pa(a)
T_inlet=np.linspace(90+273.15,200+273.15,500) #K
P_tank=(14.7-10)*6894.76 #Pa(a)
#Creating the 2D grid
P_inlet_vals,T_inlet_vals=np.meshgrid(P_inlet,T_inlet,indexing='ij')
Removal_fraction=np.zeros((len(P_inlet_vals),len(T_inlet_vals)))
#Computing removal_fraction for each point in the grid
for i in range(len(P_inlet)):
for j in range(len(T_inlet)):
Removal_fraction[i,j]=removal_fraction(P_inlet_vals[i,j],T_inlet_vals[i,j],P_tank)
字符串
我想绘制的是去除率作为P_inlet和T_inlet的函数。我在制作去除率数组时遇到了困难。Propssi函数不会接受数组。所以我必须使用for循环来传递每个值。我不确定如何构造这个数组才能在2D彩色图上正确绘制。
2条答案
按热度按时间gg0vcinb1#
要将其绘制为2D网格,您需要将Pinlet和Tinlet“扩展”为2D网格,然后计算该网格上每个点的removal_fraction。示例如下。(根据@科尔内利亚的建议,更新为使用等高线图而不是
imshow
)。x1c 0d1x的数据
字符串
在3D中:
的
型
修改OP的代码,其中计算在循环中发生:
型
iqih9akk2#
你的变量
Removal_fractions
包含一个长度为500的向量,而不是一个二维数组。你的H_inlet
也是一个长度为500的向量,而不是一个500x500的矩阵。你必须在所有压力和温度的组合上创建一个循环。字符串