Python:如何找到使用matplotlib绘制的图形的斜率?

Python:如何找到使用matplotlib绘制的图形的斜率?,第1张

概述这是我的代码: import matplotlib.pyplot as pltplt.loglog(length,time,'--') 其长度和时间是列表. 如何找到该图的斜率? 如果你有matplotlib,那么你也必须安装numpy,因为它是一个依赖关系.因此,您可以使用 numpy.polyfit找到斜率: import matplotlib.pyplot as pltimport nu 这是我的代码:
import matplotlib.pyplot as pltplt.loglog(length,time,'--')

其长度和时间是列表.

如何找到该图的斜率?

解决方法 如果你有matplotlib,那么你也必须安装numpy,因为它是一个依赖关系.因此,您可以使用 numpy.polyfit找到斜率:
import matplotlib.pyplot as pltimport numpy as nplength = np.random.random(10)length.sort()time = np.random.random(10)time.sort()slope,intercept = np.polyfit(np.log(length),np.log(time),1)print(slope)plt.loglog(length,'--')plt.show()
总结

以上是内存溢出为你收集整理的Python:如何找到使用matplotlib绘制图形的斜率?全部内容,希望文章能够帮你解决Python:如何找到使用matplotlib绘制的图形的斜率?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1207161.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-04
下一篇 2022-06-04

发表评论

登录后才能评论

评论列表(0条)

保存