[英]How to analyze data and add to plot in matplotlib
I plotted a curve and I need to do 3 things more to it.我绘制了一条曲线,我还需要对它做 3 件事。
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
plt.style.use('seaborn-bright')
print(plt.style.available)
print("NumPy version:", np.__version__)
print("Pandas version:", pd.__version__)
S_S = pd.read_excel("SSCurve.xls")
print(S_S.head())
Stress_Al = S_S['STRESS']
Strain_Al = S_S['STRAIN']
plt.scatter(Strain_Al, Stress_Al)
plt.plot(Strain_Al, Stress_Al)
plt.xlabel('Strain')
plt.ylabel('Stress (MPa)')
plt.title('Engineering Stress Vs Engineering Strain')
plt.tight_layout()
plt.show()
I need to draw a line from a certain point in the x axis that intersects the curve at certain point(something looks like this): Pic我需要从 x 轴上的某个点画一条线,在某个点与曲线相交(看起来像这样):图片
Also if possible can I find the slope of two lines (notice I am recalling the data from an xls file)另外,如果可能的话,我可以找到两条线的斜率(注意我正在从 xls 文件中调用数据)
the date are here here:日期在这里:
Thanks, appreciate your help.谢谢,感谢您的帮助。
To find the slope of a curve you can use numpy.polyfit()要找到曲线的斜率,您可以使用numpy.polyfit()
If you want the line to fit the first part of your Stress/Strain graph i suggest you to do something like this:如果您希望该线适合您的应力/应变图的第一部分,我建议您执行以下操作:
z = np.polyfit(S_S['Strain'][0:5], S_S['Stress'][0:5], 1)
If you want to plot this line you can do the following如果你想绘制这条线,你可以执行以下操作
x= Strain_Al plt.plot(z[0]*x+z[1],'--')
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
plt.style.use('seaborn-bright')
print(plt.style.available)
print("NumPy version:", np.__version__)
print("Pandas version:", pd.__version__)
S_S = pd.read_excel("SSCurve.xls")
print(S_S.head())
Stress_Al = S_S['STRESS']
Strain_Al = S_S['STRAIN']
z = np.polyfit(S_S['Strain'][0:5], S_S['Stress'][0:5], 1)
z[1] = -1
plt.scatter(Strain_Al, Stress_Al)
plt.plot(Strain_Al, Stress_Al)
plt.xlabel('Strain')
plt.ylabel('Stress (MPa)')
plt.title('Engineering Stress Vs Engineering Strain')
plt.ylim(0,7)
x= Strain_Al
plt.plot(z[0]*x+z[1],'--')
plt.tight_layout()
plt.show()
Please go to this link for the complete Jupyter Notebook请转到此链接以获取完整的 Jupyter Notebook
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.