擅长:python、mysql、java
<p>使用pandas的解决方案(可以使用<code>$ pip install pandas</code>安装)</p>
<pre><code>import pandas as pd
import matplotlib.pyplot as plt
filepath = 'path/to/file.txt'
df = pd.read_csv(filepath, sep=r'\s+')
area_key = 'AreaA,cm˛' # watch out for unicode '˛'
pi_key = 'PiA,mN/m'
ax = df.plot(area_key, pi_key, 'scatter', label='data') # can pass any plt kwargs here
x = df[area_key]
y = df[pi_key]
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
# cam override x/y labels titles here
ax.plot(xmesh, fit(xmesh), label='linear fit')
ax.legend()
plt.show()
</code></pre>
<p><a href="https://i.stack.imgur.com/Edsrv.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Edsrv.png" alt="enter image description here"/></a></p>