python - 有没有办法使用 matplotlib 插入具有重复值的系列?
问题描述
我正在尝试使用matplotlib
. 我面临的问题是失败spline
,interp1d
因为我在 x 和 y 数组中都有重复值。
我曾尝试使用 中的样条线和interp1d
函数scipy
,但都因重复值问题而失败
x1 = [0.82 0.82 0.82 0.82 0.82 0.82 0.83 0.83 0.83 0.83 0.83 0.83 0.83]
y1 = [0.93 0.93 0.93 0.93 0.94 0.94 0.94 0.94 0.94 0.94 0.94 0.94 0.94]
f = interp1d(x1, y1, kind='cubic') #this gives an error: Expect x to be a 1-D sorted array_like.
#another thing I tried
xnew = np.linspace(x1.min(),x1.max(),300)
splined = spline(x1,y1,xnew) #this gives an error: Matrix is singular
我预计插值 y 值会随着 x 的增加而逐渐增加。因此,例如,x = 0.82 对应的 y 值将是 0.931、0.932 等。我的最终目标是获得平滑的曲线。
解决方案
使用多项式怎么样?
np.poly1d(np.polyfit(x1, y1, 2))(new_x) # 2 for second degree
推荐阅读
- node.js - TypeError: domain.enter 不是函数
- c# - 如何通过 Nuget 将特定文件夹从 Razor 类库复制到目的地?
- html - Favicon 图标未显示在 Mozilla 浏览器的书签工具栏中
- c++ - 浮点异常(核心转储)cpp
- reactjs - 我收到 Expo 错误 - TypeError: Cannot read property 'props' of undefined in SwipeListView.renderCell
- vector - 检查 Vec
看看它是否全为零? - python - 在 Python 中,是否有一个 python 标准函数可以像 bash 一样将字符串解析为 argv 列表?
- python - 将 tf.nn.dropout() 与 3D-CNN 一起应用的问题
- javascript - 如何在我的角度项目中添加气候时钟小部件
- node.js - 具有联合类型的 ajv 数组