Search code examples
c++matplotlibcmakeclion

MatplotLib-cpp error : show is unexpectedly not a PyFunction


I have been trying to plot data using matplotlib-cpp. I cloned the repository and linked the library with CmakeLists.txt. Here's my 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)

All linkage with python has been done. There is no error in it. But when I plot data, I get exception as:

show is unexpectedly not a PyFunction.

here:

enter image description here

------------------------- Update -----------------------------

my function is :

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();
}

I am using Clion, Python 3.7.3 and MinGW. Need help to solve this issue.

Regards,

Khubaib


Solution

  • I solved it myself. Issue was in CmakeLists.txt:

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

    was replaced by

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