我已经对一些散点图数据进行了最合适的拟合
import numpy as np
import matplotlib.pyplot as plt
testlvals = [2.5, 2.5, 2.54, 2.61, 2.62, 2.65, 2.68, 2.74, 2.77, 2.77, 2.85, 2.87, 2.88, 2.89, 2.94, 2.96, 3.02, 3.03, 3.03, 3.19, 3.25, 3.26, 3.27, 3.3, 3.32, 3.41, 3.45, 3.53, 3.55, 3.6, 3.63, 3.66, 3.66, 3.67, 3.68, 3.71, 3.72, 3.75, 3.78, 3.79, 3.83, 3.84, 3.95, 3.98, 3.98, 4.03, 4.04, 4.06, 4.1, 4.18, 4.21, 4.23, 4.31, 4.32, 4.53, 4.54, 4.57, 4.6, 4.61, 4.69, 4.91, 4.91, 4.93, 4.99, 5.09, 5.13, 5.17, 5.17, 5.27, 5.28, 5.34, 5.36, 5.39, 5.41, 5.42, 5.44, 5.61, 5.68, 5.68, 5.72, 5.73, 5.75, 5.81, 5.87, 5.94, 5.96]
stormdll = [2.889243921893069e-05, 0.00022866553316519154, nan, 0.00013707129325248174, 0.00021835330960779531, 0.00062837761202857642, 0.00019650047630071017, 0.00010699446178025272, 0.00057187879938179747, 0.0011665035757214481, 0.00016776735479387793, 0.0013124897173367673, 0.0017014387306167212, 0.00079760282220871714, 0.000266662827251465, 0.002300090861918372, 0.0015387413878198573, 0.00082950661801858578, 0.0017190452575373278, 0.0021515348463768745, 0.00010841924191146237, 0.001157811249298408, 0.002793117055536783, 0.0059201077854461543, 0.0072200686941846313, 0.0021081707069775814, 0.0023779309754600238, 0.00082597422775368672, 0.0028797886398615048, 0.0058324203223666746, 0.0068855175445071658, nan, 0.032420016410424954, 0.029937093955166857, 0.0026630311348559647, 0.0019588293726173519, 0.013178179035275815, 0.01871886867738189, nan, 0.0090262813383890899, 0.0033087173547989967, 0.0047291994757413351, 0.0051388504281628094, 0.14723532158149036, 0.34544643808304565, nan, 0.059498245597566141, 0.05540732157485579, 0.012831295188695307, 0.03129110483607251, 0.09790170866807188, 0.01500512745113935, 0.078234868919264705, 0.36838578043111231, nan, 0.71870618281078513, 0.10610407999700187, 0.14706358285998142, nan, 0.029435942422958519, 1.4940875970666132, nan, 1.0868491045209858, 2.129202954256384, nan, 3.3586976667282427, nan, 0.20401225505683754, nan, 3.8595395153026337, 0.10641966562475162, 0.04242304708221098, 1.1431385511790786, nan, nan, 7.7179112096552576, 10.155185332954863, 33.432445492656328, 0.1308175995864734, 5.5518162778374345, 4.8955145890086884, nan, nan, 5.6004067091010015, 60.623994406240122, 1.3891652426594083]
ffig, ax = plt.subplots()
ax.semilogy([testlvals],[stormdll],'o',mfc='none',markersize=2)
idx = np.isfinite(testlvals) & np.isfinite(stormdll)
a = [testlvals[x] for x in range(len(testlvals)) if idx[x] != False]
b = [np.log(stormdll)[x] for x in range(len(stormdll)) if idx[x] != False]
ax.semilogy(testlvals, np.exp(np.poly1d(np.polyfit(a,b , 2))(testlvals)),color=color,label=str(i))
如下所示:
我想知道是否有一种pythonic方式也可以向顶部和底部边界添加最合适的线/曲线?这只是散点图和最佳拟合线之一的快照。最终目标是遍历许多散点图并找到边界轮廓,在这里我不会指出边界的形状,这在以下方面得到解决: Fit a curve to the boundary of a scatterplot 我不熟悉这种类型的编程,因此任何帮助都将非常有用!
谢谢!