以下是使用matplotlib生成图的python脚本。使用matplotlib生成平滑折线图
#!/usr/bin/python
import matplotlib.pyplot as plt
import time
import numpy as np
from scipy.interpolate import spline
# Local variables
x = []
y = []
# Open the data file for reading lines
datafile = open('testdata1.txt', 'r')
sepfile = datafile.read().split('\n')
datafile.close()
# Create a canvas to place the subgraphs
canvas = plt.figure()
rect = canvas.patch
rect.set_facecolor('white')
# Iterate through the lines and parse them
for datapair in sepfile:
if datapair:
xypair = datapair.split(' ')
x.append(int(xypair[1]))
y.append(int(xypair[3]))
# Define the matrix of 1x1 to place subplots
# Placing the plot1 on 1x1 matrix, at pos 1
sp1 = canvas.add_subplot(1,1,1, axi