使用python绘制图表

  1. 输入值:如图
    在这里插入图片描述
  2. 生成的表格:如下

在这里插入图片描述

3.代码如下

import matplotlib.pyplot as plt
import numpy as np
####################################################
#给与的值,描绘图片
A_Low = 0.1153607
B_Low = 0.001453239
C_Low = 0.000508077
T_Low = 300.8246

A_Mid = 0.1874887
B_Mid = 0.001586056
C_Mid = 0.0002653489
T_Mid = 300.8246

A_High = -15.02923
B_High = 0.0003478767
C_High = 0.01089852
T_High = 300.9223

##########################################################
def delta(P, A, B, C, T, coffd = 1):
    fTr50 =np.sqrt(T)
    fTterm= 100.24 + 0.2881*(T - 273.15)
    fPov  = P
    a = B * fTr50
    b = C * fTterm
    c = A - fPov
    # print("****************P =" + str(P)+"****************"+"\n\r")
    # print("a =" + str(a)+"\n\r")
    # print("b =" + str(b)+"\n\r")
    # print("c =" + str(c)+"\n\r")
    return (b*b -4.0 *a *c),a,b,c

def solve_formula(P, A, B, C, T, coffd = 1):
    delta_result,a,b,c = delta(P, A, B, C, T, coffd = coffd)
    # print("delta_result:" + str(delta_result)+"\n\r")
    # print("a =" + str(a)+"\n\r")
    # print("b =" + str(b)+"\n\r")
    # print("c =" + str(c)+"\n\r")
 
    if delta_result<0 :
        print("0")
        return
    #ft = - C * (100.24 + 0.2881*(T - 273.15))
    # Q1经过测试为负值,所以舍弃,Q2_sqrt为Q-P的关系
    # Q1_sqrt = (- C * (100.24 + 0.2881*(T - 273.15)) / np.sqrt(coffd) - np.sqrt(delta_result))/(2 * B * np.sqrt(T)/coffd)
    #Q2_sqrt = (ft / np.sqrt(coffd) + np.sqrt(delta_result))/(2 * B * np.sqrt(T)/coffd)
    f =(-b + np.sqrt(delta_result))/(2 * a)
    f = f * coffd
    #return np.power(Q2_sqrt, 2)
    # print("f  =" + str(f )+"\n\r")
    return f * f

#由于0到(1.6/100)*5 无解,所以从(1.6/100)*6
P1_Low = np.linspace((1.6/100)*6, 1.6, 100)  #logspace(a, b, n)生成一个数组,数据的第一个元素值为a,最后一个元素为b,n是总采样点数
P1_Mid = np.linspace(1.6, 15, 1000)
P1_High = np.linspace(15, 31, 1000)


Q_Low = []  #一种有序、可变的数据结构,可以存储不同类型的元素
Q_Mid = []
Q_High = []


for p in P1_Low:
    temp_low = solve_formula(p, A_Low, B_Low, C_Low, T_Low)
    #print("temp_low =" + str(temp_low)+"\n\r")
    Q_Low.append(temp_low)
for p in P1_Mid:
    temp_Mid= solve_formula(p, A_Mid, B_Mid, C_Mid, T_Mid)
    #print("temp_Mid =" + str(temp_Mid)+"\n\r")
    Q_Mid.append(temp_Mid)
    #Q_Mid.append(solve_formula(p, A_Mid, B_Mid, C_Mid, T_Mid))
for p in P1_High:
    temp_High= solve_formula(p, A_High, B_High, C_High, T_High)
    #print("temp_High =" + str(temp_High)+"\n\r")
    Q_High.append(temp_High)

   # Q_High.append(solve_formula(p, A_High, B_High, C_High, T_High))



#P1 = float(13)  #输入P1的值
P1 = input("请输入:")
P1 = float(P1)
print("你输入的内容是:",P1)
if (P1>=(1.6/100)*6) & (P1 < 1.6):
    print(solve_formula(P1, A_Low, B_Low, C_Low, T_Low))
elif (P1 >=1.6) & (P1 < 15):
    print(solve_formula(P1, A_Mid, B_Mid, C_Mid, T_Mid))
elif (P1>=15) & (P1<=31) :
    print(solve_formula(P1, A_High, B_High, C_High, T_High))
else:
    print("输入P1值无效!由于0到(1.6/100)*5 无解,所以P1的范围为" + str((1.6/100)*6) + "<=P1<=" + str(31))

#显示图表
plt.figure(0) 
plt.plot(P1_Low, Q_Low, '-', label='Low')
plt.plot(P1_Mid, Q_Mid, '-', label='Mid')
plt.plot(P1_High, Q_High, '-', label='High')

#画图例
plt.legend()
#显示中文
plt.rcParams['font.sans-serif'] = ['SimHei']
#指定坐标轴名称
plt.xlabel('P1')
plt.ylabel('Qm')
#显示
plt.show()




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值