0

I am a newbie to Python. I've been dabbling in Matplotlib for quite a while. Here's the problem I ran into. I need to plot two different graphs in a row. I tried plt.subplots(1,2,1) or something like this, but this seems not to have worked.

I want to have two sets of graphs Pk=f(Dk), Pk=f(Subcooling) depicted at the end of the program. Whenever I want to build a graph using only one parameter, it works. That said, I can't bring it to plot a graph for each variable. How can I tweak the code to achieve this end?

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import math
import pyXSteam.XSteam
from pyXSteam.XSteam import XSteam
sns.set_style("ticks",{'grid.linestyle': '--'})
sns.color_palette("Spectral", as_cmap=True)

steamTable = XSteam(XSteam.UNIT_SYSTEM_MKS) # m/kg/sec/°C/bar/W
A = float(input('Define the heat exchange area, sq.m: ')) #3000 m2
d_in = float(input('Define the inner diameter of a single HE tube, mm: ')) #20mm
CF = float(input('Define the cleanliness factor of the HE (0.8,0.85,0.9 etc): ')) #0.85
Gw=float(input('Define the CW flow, t/hr: ')) #13000 t/hr
z=float(input('Define the number of passes: ')) #1
rho=float(input('Define the density of the liquid, kg/m3: ')) #1000 kg/m3
N=float(input('Define the number of tubes in the HE: ')) #5096
def w():
    return ((Gw*1000/3600)*z*4*1000000)/(rho*math.pi*((d_in)**2)*N) #2.26 m/s - water velocity inside the tubes
Tcwin=float(input('Define some initial value of Tcwin:')) #20
#Tcwin=20 #assume some initial value for Tcwin
Dk=float(input('Define the max steam load, t/hr: ')) #274.18
def Cp():
    return steamTable.CpL_t(Tcwin)
def Ts():
    return np.vectorize(Tsat_theor)
def Psat_theor():
    return 100*steamTable.psat_t(Tsat_theor)
def dk():
    return Dk*1000/(A*3.600)
def K():
    return CF * 4070 * ((1.1 * w() / (d_in ** 0.25)) ** (0.12 * CF * (1 + 0.15 * Tcwin))) * (1 - (((35 - Tcwin) ** 2) * (0.52 - 0.0072 * dk) * (CF ** 0.5)) / 1000)
def Tcwout_theor():
    return Tcwin+(Dk*2225/(Gw*Cp()))
def Subcooling_theor():
    return (Tcwout_theor - Tcwin) / ((math.e ** (K * A / (Cp() * (Gw * 1000 / 3600) * 1000)))-1)
def TR_theor():
    return (Tcwout_theor - Tcwin)
def Tsat_theor():
    return (Tcwout_theor + Subcooling_theor)
def LMTD_theor():
    return TR_theor/math.log((Tsat_theor()-Tcwin)/(Tsat_theor()-Tcwout_theor()))
X = np.arange(Dk*0.1,Dk*1.1,Dk*0.1)
for Tcwin in np.arange(17,31,2):
    Y = []
    for Dk in X:
        dk = (Dk * 1000 / (A * 3.600)) #calculate the relative steam load
        K = CF * 4070 * ((1.1 * w() / (d_in ** 0.25)) ** (0.12 * CF * (1 + 0.15 * Tcwin))) * (1 - (((35 - Tcwin) ** 2) * (0.52 - 0.0072 * dk) * (CF ** 0.5)) / 1000)
        n = (K * A) / (Cp() * Gw * 1000)
        Tcwout_theor = Tcwin + (Dk * 2225 / (Cp() * Gw))
        Subcooling_theor = (Tcwout_theor - Tcwin) / ((math.e ** (K * A / (Cp() * (Gw * 1000 / 3600) * 1000)))-1)
        TR_theor = (Tcwout_theor - Tcwin)
        Tsat_theor = (Tcwout_theor + Subcooling_theor)
        Y.append(Psat_theor())
    plt.grid(True, which="both", ls="--", c='gray')
    plt.plot(X, Y)
    plt.pause(0.25)
plt.xlabel(r'$D_{k}$' + ',т/ч', loc='right')
plt.ylabel(r'$P_{k}$' + ',кПа', rotation=0, loc='top')
plt.legend([r'$t_{1в}$' + '=17 \N{DEGREE SIGN}С',
            r'$t_{1в}$' + '=19 \N{DEGREE SIGN}С',
            r'$t_{1в}$' + '=21 \N{DEGREE SIGN}С',
            r'$t_{1в}$' + '=23 \N{DEGREE SIGN}С',
            r'$t_{1в}$' + '=25 \N{DEGREE SIGN}С',
            r'$t_{1в}$' + '=27 \N{DEGREE SIGN}С',
            r'$t_{1в}$' + '=29 \N{DEGREE SIGN}С'])
plt.title(r'$P_{k}$' + '=f(' + '$D_{k}$' + ')')
sns.despine()
plt.subplots_adjust()
plt.show()



0 Answers0