- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我在尝试通过我的数据拟合平均曲线以求出长度时遇到了问题。我在一个 Pandas 数据框中有很多 X、Y 点,看起来像这样:
x = np.asarray([731501.13, 731430.24, 731360.29, 731289.36, 731909.72, 731827.89,
731742. , 731657.74, 731577.95, 731502.64, 731430.39, 731359.12,
731287.3 , 731214.21, 732015.59, 731966.88, 731902.67, 731826.31,
731743.79, 731660.94, 731581.29, 731505.4 , 731431.95, 732048.71,
732026.66, 731995.46, 731952.18, 731894.29, 731823.58, 731745.16,
732149.61, 732091.53, 732052.98, 732026.82, 732005.17, 731977.63,
732691.84, 732596.62, 732499.45, 732401.62, 732306.18, 732218.35,
732141.82, 732080.91, 732038.21, 732009.08, 733023.08, 732951.99,
732873.32, 732787.51])
y = np.asarray([7873771.69, 7873705.34, 7873638.03, 7873571.73, 7874082.33,
7874027.2 , 7873976.22, 7873923.58, 7873866.35, 7873804.53,
7873739.58, 7873673.62, 7873608.23, 7873544.15, 7874286.21,
7874197.15, 7874123.96, 7874063.21, 7874008.78, 7873954.69,
7873897.31, 7873836.09, 7873772.38, 7874564.62, 7874448.23,
7874341.23, 7874246.59, 7874166.93, 7874100.4 , 7874041.77,
7874912.56, 7874833.09, 7874733.62, 7874621.43, 7874504.65,
7874393.89, 7875225.26, 7875183.85, 7875144.42, 7875105.69,
7875064.49, 7875015.5 , 7874954.94, 7874878.36, 7874783.13,
7874674. , 7875476.18, 7875410.05, 7875351.67, 7875300.61])
x 和 y 是 map View 坐标,我想计算长度。我可以对欧几里得距离进行编码,但是因为这些点是分散的并且不是一个接一个的点,所以我在尝试通过它拟合一条移动线时遇到了麻烦。我试过 polyfit 但这主要产生一条直线,即使是更高的度数,例如:
from numpy.polynomial.polynomial import polyfit
import numpy as np
import matplotlib.pyplot as plt
z = np.polyfit(x,y,10)
p = np.poly1d(z)
plt.scatter(x,y, marker='x')
plt.scatter(x, p(x), marker='.')
plt.show()
这是为了演示我的意思 1
如有任何帮助,我们将不胜感激!
最佳答案
这将是一个适合您的数据的经验函数:
import matplotlib.pyplot as plt
import numpy as np
from scipy.optimize import curve_fit
x = np.asarray([731501.13, 731430.24, 731360.29, 731289.36, 731909.72, 731827.89,
731742. , 731657.74, 731577.95, 731502.64, 731430.39, 731359.12,
731287.3 , 731214.21, 732015.59, 731966.88, 731902.67, 731826.31,
731743.79, 731660.94, 731581.29, 731505.4 , 731431.95, 732048.71,
732026.66, 731995.46, 731952.18, 731894.29, 731823.58, 731745.16,
732149.61, 732091.53, 732052.98, 732026.82, 732005.17, 731977.63,
732691.84, 732596.62, 732499.45, 732401.62, 732306.18, 732218.35,
732141.82, 732080.91, 732038.21, 732009.08, 733023.08, 732951.99,
732873.32, 732787.51])/732 -1000
y = np.asarray([7873771.69, 7873705.34, 7873638.03, 7873571.73, 7874082.33,
7874027.2 , 7873976.22, 7873923.58, 7873866.35, 7873804.53,
7873739.58, 7873673.62, 7873608.23, 7873544.15, 7874286.21,
7874197.15, 7874123.96, 7874063.21, 7874008.78, 7873954.69,
7873897.31, 7873836.09, 7873772.38, 7874564.62, 7874448.23,
7874341.23, 7874246.59, 7874166.93, 7874100.4 , 7874041.77,
7874912.56, 7874833.09, 7874733.62, 7874621.43, 7874504.65,
7874393.89, 7875225.26, 7875183.85, 7875144.42, 7875105.69,
7875064.49, 7875015.5 , 7874954.94, 7874878.36, 7874783.13,
7874674. , 7875476.18, 7875410.05, 7875351.67, 7875300.61])/7873 - 1000
def my_func( x, x0, y0, a, b, c, t, s):
xs = x-x0
p = a * xs**3 + b * xs**2 + c * xs + y0
t = t * np.tanh( s * xs )
return p + t
xth = np.linspace( -1.15, 1.5, 50 )
yth = my_func( xth, 0.03, 0.18, .01, 0, 0.05, .05 , 10)
sol, err = curve_fit( my_func, x, y, p0=[0.03, 0.18, .01, 0, 0.05, .05 , 10] )
print sol
fig = plt.figure()
ax = fig.add_subplot( 1, 1, 1 )
ax.scatter( x, y )
ax.plot( xth, yth )
ax.plot( xth, my_func( xth, *sol) )
plt.show()
给予
>>[ 2.86281016e-02 1.95292660e-01 9.62290944e-03 -1.26304655e-02 5.11281073e-02 4.63955967e-02 1.02260568e+01]
和
关于python - 有没有办法通过分散的 X、Y 坐标绘制 'tight' 最佳拟合线?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56277118/
我有一个数据文件,我想创建一个 pm3d map 点阵。代码: set term pngcairo size 800,600 set out "test.png" set pm3d map splot
这句话我听过很多次了。这是什么意思? 举个例子会有所帮助。 最佳答案 来自Wiktionary : (计算)在汇编语言中,包含少量指令并迭代多次的循环。 (计算)此类循环大量使用 I/O 或处理资源,
具有键/值对“紧密”重复模式的字符串(对于此示例,键是“name”,值应该是单个小写单词) string text = "name: abc name: def name: ghi name: jkl
这是我的 HTML 的结构: Some text Not much text Some text Not much text Some text Not much text 我有三个
我经常使用 matplotlib 生成单个图形,这些图形应该垂直或水平对齐,例如在 LaTeX 文档中。我的目标是: 避免在所有图中留出过多的边距或剪裁。对于独立图形,这可以通过使用 bbox_inc
好的,所以我在这里被观察者模式困住了,我读过的几乎所有教程都告诉主题类订阅观察者。 但是考虑到封装,这怎么能不紧密耦合呢?他们仍然相互依赖,不是吗? 我的意思是,subject Class必须知道观察
根据documentation , ax.autoscale(tight=True) 应该 If True, set view limits to data limits; 与 ax.axis('ti
似乎 savefig 中的 bbox_inches='tight' 选项忽略了没有文本的注释。这是我的示例代码 import matplotlib.pyplot as plt fig = plt.fi
我正在尝试创建我的网页,但我遇到了 float 问题。 这是我的 HTML 代码: InformacjeAutokoder.pl jest obecnie najbardziej innowa
我有一个程序可以将其进度打印到控制台。每 20 步,它会打印步数,例如 10 20 30 等,但在此范围内,它会打印一个点。这是使用末尾带有逗号的 print 语句打印的 (python 2.x)
当您在 Matplotlib 的 savefig() 函数中设置 bbox_inches = 'tight' 时,它会尝试找到封装图形窗口中所有内容的最紧密的边界框。不幸的是,最紧密的边界框似乎包含不
我在 ipython 笔记本中使用以下代码将条形图保存为 .png 文件: plt.savefig(文件名, bbox_inches='tight') 它在我的电脑上运行,我试过在另一台电脑上运行脚本
我必须绘制一个矢量图,我只想看到没有轴、标题等的矢量,所以我尝试这样做: pyplot.figure(None, figsize=(10, 16), dpi=100) pyplot.quiver(da
你能给我解释一下下面的短语(摘自 an answer to Stack Overflow question What are the differences between Deferred, Pro
我正在开发一个 WordPress 插件,并努力确保最佳实践。我有两个类,我的插件类“Jargonaut”是必需的,然后是另一个名为“Dictionary”的类,它随 require_once() 包
我一点也不擅长设计,我只是想在 Bootstrap 4 中进行简单的表单对齐;我根本没有做任何定制,只是很乐意接受框架给我的任何东西。 我已经通读了表单文档,变体的数量非常困惑,到目前为止,我尝试的一
我在尝试通过我的数据拟合平均曲线以求出长度时遇到了问题。我在一个 Pandas 数据框中有很多 X、Y 点,看起来像这样: x = np.asarray([731501.13, 731430.24,
我下载了 Enhanced Tight VNC Viewer ( http://www.karlrunge.com/x11vnc/ssvnc.html ) 并按照说明将我本地机器(运行 Win 7)上
本文整理了Java中com.sun.msv.datatype.xsd.WhiteSpaceProcessor.tightness()方法的一些代码示例,展示了WhiteSpaceProcessor.t
我正在制作一个嵌入 latex 中的出版物质量图,我希望在大小和字体方面非常精确(以便文章中的字体与图中的字体大小相同)。为了防止绘图在 latex 中缩放,我想要它的确切尺寸,但我不能。这是我的代码
我是一名优秀的程序员,十分优秀!