python - numpy switch axes and reshape
问题描述
I have some geophysical data in a 2d numpy array. My target is to filter just one trace data and plot it. I am able to do it, but I need to switch my axes.
This is what I have for now:
So the shape is: (436,1771).
And this is what I have done:
x = arr[:,1]
fig,ax = plt.subplots()
ax.plot(x,'k-')
ax.set_xlim(0,500)
plt.show()
Now that I have my trace, I want to switch my axes so I can see the trace vertically, but I´m having problems doing that and I get errors.
x2 = np.swapaxes(x,0,1)
I get an error saying " numpy.AxisError: axis2: axis 1 is out of bounds for array of dimension 1". I understand that this is because the shape of the array.
So, how can I reshape my arrar into (1771,436) and transpose the data?
解决方案
Maybe try something along these lines?
plt.plot(arr[:,1], range(len(arr[:,1])),'k-')
Instead of pushing all the Y coordinates, I put all your Y-data as X data and want with a linear scaled axis along the Y-axis done with the range() command. If you just put Y-data, it will assume range(len(Y-data)) as X-data, which is what happens in your example. feel free to correct me if there is a mistake
推荐阅读
- python - Django 没有检测到我的模型中的变化
- c# - 如何在我的 ASP Net Core 5.0 项目中比较“ß”和“ss”?
- sql - SQL Server 计算数据窗口中的聚合差异
- angular - Ace 编辑器 setFontSize 不会更改装订线单元图标大小
- c++ - 可变参数模板函数的 1-arg 重载有用吗?它应该使用魔法 && 参考吗?在这种情况下是否发生了复制省略?
- text - 后处理器发生故障时更改 CNC 代码的便捷方法
- bash - 字符串中确切点的 Grep 变量
- c - 通过指向数组的指针返回结果
- airflow - 如何在 Airflow 中将 XCom 值用作运算符外部的全局变量
- linux - 如何使用 jq 获取数组值