开发者社区> 问答> 正文

绘制scalogram如何选择级别在contourf

我试着画出一个信号的连续小波变换的输出。信号只是一个余弦波,其频率随时间减小。我只是用它来测试绘图函数。 我有一个函数,绘图的scalogram的CWT,但我正在努力如何选择正确的水平范围,用于我的等高线。 我想知道的是: 感谢任何反馈/意见/答案,如果你看到任何错误。非常感谢! 我用来创建情节的函数:



def plot_wavelet(ax, time2, signal, scales, waveletname = 'cmor', 
      cmap =plt.cm.seismic, title = '', ylabel = '', xlabel = ''):

    dt=time2
    coefficients, frequencies = pywt.cwt(signal, scales, waveletname, dt)
    print ("coeff shape is:",coefficients.shape)
    print ("frequency shape is:", frequencies.shape)
    power = (abs(coefficients)) ** 2
    period = frequencies

    # different level lists to test 
    levels = [0.015625, 0.03125, 0.0625, 0.125, 0.25, 0.5, 1, 2, 4, 8, 16] #option 1
    #levels = [0.015625, 0.03125, 0.0625, 0.125, 0.25, 0.5, 1] #option 2

    contourlevels = np.log2(levels) #convert to log2 for plotting
    time=range(2048) # Sampling frequency is 2048, so this is a 1 second sample

    im = ax.contourf(time, np.log2(period), np.log2(power), contourlevels, extend='both',cmap=cmap)

    ax.set_title(title, fontsize=20)
    ax.set_ylabel(ylabel, fontsize=18)
    ax.set_xlabel(xlabel, fontsize=18)

    yticks = 2**np.arange(np.ceil(np.log2(period.min())), np.ceil(np.log2(period.max())))

    ax.set_yticks(np.log2(yticks)) #original
    ax.set_yticklabels(yticks) #original
    ax.invert_yaxis()

    ylim = ax.get_ylim()
    cbar_ax = fig.add_axes([0.95, 0.5, 0.03, 0.25])
    fig.colorbar(im, cax=cbar_ax, orientation="vertical")

    return yticks, ylim

下面两个图的唯一区别是使用的关卡,其他的都是一样的: 这是一个级别=[0.015625,0.03125,0.0625,0.125,0.25,0.5,1,2,4,8,16]的图。

这是级别=[0.015625,0.03125,0.0625,0.125,0.25,0.5,1]的图。

问题来源StackOverflow 地址:/questions/59379448/plotting-a-scalogram-how-to-select-levels-in-contourf

展开
收起
kun坤 2019-12-30 09:30:31 580 0
0 条回答
写回答
取消 提交回答
问答地址:
问答排行榜
最热
最新

相关电子书

更多
图计算优化技术探索 立即下载
低代码开发师(初级)实战教程 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载