以下是使用matplotlib生成绘图的python脚本.
#!/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 …Run Code Online (Sandbox Code Playgroud) 我正在尝试模拟Excel
插入>散布>带有平滑线条和标记的散布
Matplotlib 中的命令
scipy 函数interpolate创建了类似的效果,并提供了一些很好的示例来说明如何简单地实现此功能: 如何在 matplotlib 中绘制三次样条曲线
然而,Excel 的样条算法也能够仅通过三个点生成平滑曲线(例如 x = [0,1,2] y = [4,2,1]);并且不可能用三次样条来做到这一点。
我看过一些讨论,建议 Excel 算法使用 Catmull-Rom 样条线;但不太了解这些,也不了解它们如何适应 Matplotlib: http://answers.microsoft.com/en-us/office/forum/office_2007-excel/how-does-excel-plot-smooth-curves /c751e8ff-9f99-4ac7-a74a-fba41ac80300
是否有一种简单的方法可以修改上述示例,以使用插值库通过三个或更多点实现平滑曲线?
非常感谢