C++ 调用matplotlibcpp 绘图配置说明

环境:ubuntu20 , vscode

1、配置python环境,安装python3;

sudo apt-get install python3-dev

2、配置 numpy 和 matplotlib;

sudo apt-get update
sudo apt-get install python3-numpy
sudo apt-get install python3-matplotlib

 检查是否安装成功:

终端进入python环境下:import matplotlib.pyplot as plt

3、下载matplotlibcpp包,这个包可以放在任何位置,后续把路径添加就OK;

git clone https://github.com/lava/matplotlib-cpp

4、使用VScode

        (1)、c_cpp_properties.json文件,修改如下:

C++ 调用matplotlibcpp 绘图配置说明_第1张图片

 找到”matplotlib-cpp“的路径:

         (2)、cmake.list修改


 find_package(Python3 COMPONENTS Development NumPy)
 
 target_include_directories(test_every PRIVATE ${Python2_INCLUDE_DIRS} ${Python2_NumPy_INCLUDE_DIRS})
 
 include_directories("/home/bobo/third_storage/matplotlib-cpp/")
 
 target_link_libraries(test_every Python3::Python Python3::NumPy)

其中“test_every" 为自己的可执行文件,一定放在该可执行文件add_executable的后面

5、测试,写可执行文件

#include "matplotlibcpp.h"
#include 

namespace plt = matplotlibcpp;

int main()
{
    // Prepare data.
    int n = 5000;
    std::vector x(n), y(n), z(n), w(n,2);
    for(int i=0; i

C++ 调用matplotlibcpp 绘图配置说明_第2张图片

 

你可能感兴趣的:(matplotlib,python,开发语言)