Sample Python Code
The following code can be used to produce a plot of pressure versus time. This is the most basic code needed to see transient data, but the flexibility exists to script a more detailed file allowing for flexibility such as comparing temperature between ports, generating a separate figure for each port, etc.
import numpy as np import matplotlib.pyplot as pltmyFile = 'carbon.txt' data = np.genfromtxt(myFile, skip_header=2, skip_footer = 1)# Time (minutes) x=data[:,2] x = x/1000/60# Pressure (Torr) y=data[:,0]plt.plot(x,y,'ko') plt.ylabel('Pressure (Torr)') plt.xlabel('time (minutes)') plt.show()
Sample Code Explanation
import numpy as np import matplotlib.pyplot as plt
Import is needed to load the modules containing functions to be used — in this case, numerical and plotting functions. Coding is easier if abbreviations such as np and plt are used.
myFile = 'carbon.txt' data = np.genfromtxt(myFile, skip_header=2, skip_footer = 1)
MyFile is a variable name for the .txt file to be read. As long as the .txt file and the script file are in the same directory, the script file can run automatically by double-clicking the script file after the correct file has been hard-coded.
The genfromtxt() function allows for the text file to be converted into a numerical matrix.
The skip_header setting allows for the first 2 rows of data to be excluded from the matrix. As shown in the following figure, the first row of data is ASCII art created by the PuTTY program, and the second row of data are the column labels — neither of which are numerical data.
The skip_footer setting is needed because, when the .txt file is read in real time, the entire last row of data may not be complete. This causes problems for creating the matrix and needs to be excluded. This means that the last half-second of data is not displayed when the data are viewed in real time.
![]() |
Exclude the first two rows of data |
Sample of Transient Data |
# Time (minutes) x=data[:,2] x = x/1000/60
Data File Column Descriptions identifies the columns of data recorded. The fourth column of data contains time in milliseconds, however, the first index in Python is 0; therefore,
data[:,3] captures all of the rows (:) in the fourth column.
plt.plot(x,y,'ko') plt.ylabel('Pressure (Torr)') plt.xlabel('time (minutes)') plt.show()
The above code shows the syntax for plotting. The label 'ko' indicates filled black circles.