使用librosa.display.specshow实时运行matplotlib

时间:2019-07-13 10:38:16

标签: python-3.x matplotlib

我有一个电子应用程序,该应用程序启动一个烧瓶服务器,该服务器从给定的音频创建映像,该映像与pyinstaller捆绑在一起,问题是当我使用以下代码时,它将为matplotlib启动一个单独的过程。

解决方案是不使用matplotlib中的pyplot,我是matplotlib的新手,我不知道该怎么做。

我有以下代码,该代码可以作为方面使用,但存在此分离过程的错误:

    plt.figure()
    plt.subplots(figsize=figsize)
    librosa.display.specshow(librosa.power_to_db(mel_spec, ref=np.max), fmax=8000)
    plt.axis('off')
    plt.subplots_adjust(top=1, bottom=0, right=1, left=0, hspace=0, wspace=0)
    plt.margins(0, 0)

    predict_img = io.BytesIO()
    plt.savefig(predict_img, format="jpeg")
    predict_img.seek(0)
    plt.close('all')

enter image description here

我有以下代码,该代码创建了错误的图片,但没有启动分离过程:

    fig = Figure(figsize=figsize)
    fig.add_subPlot()
    librosa.display.specshow(librosa.power_to_db(mel_spec, ref=np.max), fmax=8000)

    predict_img = io.BytesIO()
    fig.savefig(os.getcwd() + "/images/silent-" + str(random.randrange(0, 1000)) + ".png", format='png')
    fig.savefig(predict_img, format="png")
    predict_img.seek(0)

enter image description here

0 个答案:

没有答案