MatplotLib-cpp error : show is unexpectedly not a PyFunction

MatplotLib-cpp error : show is unexpectedly not a PyFunction

我一直在尝试使用 matplotlib-cpp 绘制数据。我克隆了存储库并将库与 CmakeLists.txt 链接起来。这是我的 cmakelists.txt :

cmake_minimum_required(VERSION 3.13)
project(beep)

set(CMAKE_CXX_STANDARD 14)
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -g -ftest-coverage -fprofile-arcs" )
link_directories(C:/MinGW/lib)
find_package (Python3 COMPONENTS Interpreter NumPy)
include_directories(C:/Python37/include/)
link_libraries(C:/Python37/libs/python3.lib Python3::NumPy)

include_directories(kissfft kissfft/tools matplotlib-cpp )
add_executable(beep kissfft matplotlib-cpp kissfft/tools/kiss_fftr.c kissfft/_kiss_fft_guts.h Beep_Generator.cpp plottingVector.h)

与python的所有链接都已完成。它没有错误。但是当我绘制数据时,出现异常:

show is unexpectedly not a PyFunction.

此处:

------------------------更新---------------- ----------

我的函数是:

void mainfunc() {
    SetConsoleTitleA("PCM Audio Example");

    int nfft = 528000;

    plotting_vector output_data;


    kiss_fftr_cfg cfg = kiss_fftr_alloc(nfft, 0, 0, 0);

    kiss_fft_scalar *cx_in = new kiss_fft_scalar[nfft];
    kiss_fft_cpx *cx_out = new kiss_fft_cpx[nfft / 2 + 1];


    std::string filename = "mixed";

    BitDepth *server_buffer = new BitDepth[NUM_SAMPLES];
    BitDepth *client_buffer = new BitDepth[NUM_SAMPLES];

    BitDepth *buffer = new BitDepth[528000];

    memset(server_buffer, 0, NUM_SAMPLES * sizeof(BitDepth));
    memset(client_buffer, 0, NUM_SAMPLES * sizeof(BitDepth));

    memset(buffer, 0, NUM_SAMPLES * sizeof(BitDepth));

    server_sineWave(server_buffer, 500.0);
    client_sineWave(client_buffer, 0.0);

    mix(buffer, server_buffer, client_buffer, 200);

    /* Here mixing is done and output is in buffer array ,
    Now we shall process frame based using gist*/

    for (int i = 0; i < 528000; i++) {
        cx_in[i] = static_cast<float>(buffer[i]);
    }


    kiss_fftr(cfg, cx_in, cx_out);

    for (int i = 0; i < ((nfft / 2) + 1); i++) {
//        cout << "Real value :  " << cx_out[i].r << " Imaginary Value : " << cx_out[i].i << endl;
        output_data.r.push_back(cx_out[i].r);
        output_data.i.push_back(cx_out[i].i);

    }


    try {
        plt::plot(output_data.r);
        plt::show();
    }
    catch (std::exception &e) {
        cout << e.what() << endl;
    }



    writeWaveFile(std::string(filename + std::string(".wav")).c_str(), buffer);
    delete[] buffer;

    std::cout << filename << ".wav written!" << std::endl;
    std::cin.get();
}

我正在使用 Clion、Python 3.7.3 和 MinGW。需要帮助解决这个问题。

此致,

胡拜布

我自己解决了。问题在 CmakeLists.txt:

link_libraries(C:/Python37/libs/python3.lib Python3::NumPy)

取代
link_libraries(C:/Python37/libs/libpython37.a Python3::NumPy)