用Python写一个程序实现3D fft瀑布

问题描述 投票:0回答:0

我正在尝试从 Google 导入和使用开源的瀑布流,但出现错误。我该如何解决这个问题?

我该如何纠正?我想将数据加载到 Pandas 中并绘制 3D fft 瀑布图。但我不能,因为我得到一个错误

# ValueError: not enough values to unpack (expected 2, got 1)
# please solve
# 
#I'm trying to implement a 3D FFT waterfall plot in Python, but I get an error. How can I fix #it? An error appears about the value. If anyone knows how to fix this, I would appreciate it if #you could fix it. import numpy as np import matplotlib.pyplot as plt import pandas as pd from matplotlib.collections import LineCollection from mpl_toolkits.mplot3d import Axes3D

def waterfall_plot(fig,ax,X,Y,Z):
    '''
    Make a waterfall plot
    Input:
        fig,ax : matplotlib figure and axes to populate
        Z : n,m numpy array. Must be a 2d array even if only one line should be plotted
        X,Y : n,m array
    '''
    # 모든 플롯에 대해 정규화를 동일한 값으로 설정
    norm = plt.Normalize(Z.min().min(), Z.max().max())
    # 가장 작은 치수에 대해 항상 반복되는 크기 확인
    n,m = Z.shape
    if n\>m:
        X=X.T; Y=Y.T; Z=Z.T
        m,n = n,m

    for j in range(n):
        # X, Z를 쌍으로 재구성
        points = np.array(\[X\[j,:\], Z\[j,:\]\]).T.reshape(-1, 1, 2)
        segments = np.concatenate(\[points\[:-1\], points\[1:\]\], axis=1)        
        lc = LineCollection(segments, cmap='plasma', norm=norm)
        # Set the values used for colormapping
        lc.set_array((Z\[j,1:\]+Z\[j,:-1\])/2)
        lc.set_linewidth(2) # set linewidth a little larger to see properly the colormap variation
        line = ax.add_collection3d(lc,zs=(Y\[j,1:\]+Y\[j,:-1\])/2, zdir='y') # add line to axes

    fig.colorbar(lc) # add colorbar, as the normalization is the same for all, it doesent matter which of the lc objects we use


sample = pd.read_csv('c:/samples/sample3.csv') array = np.array(sample) where_are_NaNs = np.isnan(array) array\[where_are_NaNs\] = 0

sr = 2000 ts = 1 / sr

x = array\[:, 1\] y = array\[:, 2\] z = array\[:, 3\] t = np.arange(0, np.size(x)) \* ts

nfft = np.size(x)

X = np.fft.fft(x) Y = np.fft.fft(y) Z = np.fft.fft(z)

N = len(X) n = np.arange(N) T = N / sr freq = n / T

n_oneside = N // 2 f_oneside = freq\[:n_oneside\]

x1 = f_oneside y1 = abs(X\[:N // 2\])

# Generate data
# x = np.linspace(-2,2, 500)
# y = np.linspace(-2,2, 40)
# X,Y = np.meshgrid(x,y)
# Z = np.sin(X\*\*2+Y\*\*2)
# Generate waterfall plot fig = plt.figure() ax = fig.add_subplot(111, projection='3d') waterfall_plot(fig,ax,t,x1,y1) ax.set_xlabel('X') ; ax.set_xlim3d(-2,2) ax.set_ylabel('Y') ; ax.set_ylim3d(-2,2) ax.set_zlabel('Z') ; ax.set_zlim3d(-1,1)

plt.show()
python pandas 3d fft
© www.soinside.com 2019 - 2024. All rights reserved.