擅长:python、mysql、java
<p>下面是一个使用您提供的数据的解决方案。访问文件内容时,只需跳过文件中的第一行即可</p>
<pre><code>import numpy as np
import matplotlib.pyplot as plt
with open("file.txt") as f:
lines = f.readlines()
x = [float(line.split()[1]) for line in lines[1:]] # [1:] skips the first line
y = [float(line.split()[4]) for line in lines[1:]]
xmesh = np.linspace(min(x), max(x), 100) # Create a fine x mesh for fitting
fit = np.poly1d(np.polyfit(x,y,1)) # Making a linear fit
plt.plot(x, y, 'bo', label='Actual data') # Plotting actual data
plt.plot(xmesh, fit(xmesh), '-b', label='Linear fit') # Plotting fit
plt.xlabel('Area (cm)')
plt.ylabel('Pi A (mN/m)')
plt.legend()
</code></pre>
<p><strong>输出</strong></p>
<p><a href="https://i.stack.imgur.com/DCLLC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DCLLC.png" alt="enter image description here"/></a></p>