日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

windows下vscode環境c++利用matplotlibcpp繪圖_C 語言

作者:yuniversi ? 更新時間: 2023-05-14 編程語言

1. 下載matplotlibcpp

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

2. matplotlibcpp測試代碼

#include "matplotlibcpp.h"
namespace plt = matplotlibcpp;
int main() {
    plt::plot({1,3,2,4});
    plt::show();
}

3. 配置.vscode

3.1 配置tasks.json

在args里面添加如下路徑,根據自己的實際路徑進行配置。

// matplotlibcpp
"-I", "F:\\c++_libraries\\matplotlibcpp",  // matplotlibcpp.h路徑
"-I", "F:\\python3.7.8\\include",  // Python.h路徑
"-I", "F:\\python3.7.8\\Lib\\site-packages\\numpy\\core\\include",  // numpy/arrayobject.h路徑
"-L", "F:\\python3.7.8",  // python37.dll的所在目錄
"-l", "python37"  // python37.dll動態庫

3.2 配置c_cpp_properties.json

在includePath中添加如下路徑,根據自己的實際路徑進行配置。

// matplotlibcpp
"F:\\c++_libraries\\matplotlibcpp",  // matplotlibcpp.h路徑
"F:\\python3.7.8\\include",  // Python.h路徑
"F:\\python3.7.8\\Lib\\site-packages\\numpy\\core\\include"  // numpy/arrayobject.h路徑

4. 注釋掉matplotlibcpp.h中兩行代碼

配置完以后,如果直接運行,會報錯matplotlibcpp.h中有兩行重復定義,注釋即可。官方代碼也給出了提示。

// Sanity checks; comment them out or change the numpy type below if you're compiling on
// a platform where they don't apply
static_assert(sizeof(long long) == 8);
// template <> struct select_npy_type<long long> { const static NPY_TYPES type = NPY_INT64; };
static_assert(sizeof(unsigned long long) == 8);
// template <> struct select_npy_type<unsigned long long> { const static NPY_TYPES type = NPY_UINT64; };

5. 運行

最后運行即可,得到如下效果。

原文鏈接:https://blog.csdn.net/weixin_43769166/article/details/118365416

欄目分類
最近更新