windows下vscode環(huán)境c++利用matplotlibcpp繪圖
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里面添加如下路徑,根據(jù)自己的實際路徑進行配置。
// 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動態(tài)庫
3.2 配置c_cpp_properties.json
在includePath中添加如下路徑,根據(jù)自己的實際路徑進行配置。
// 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中有兩行重復(fù)定義,注釋即可。官方代碼也給出了提示。
// 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. 運行
最后運行即可,得到如下效果。
到此這篇關(guān)于windows下vscode環(huán)境c++利用matplotlibcpp繪圖的文章就介紹到這了,更多相關(guān)vscode環(huán)境c++ matplotlibcpp繪圖內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
C++ OpenCV實現(xiàn)抖音"藍線挑戰(zhàn)"特效
這篇文章主要介紹了如何使用OpenCV C++ 實現(xiàn)抖音上的特效“藍線挑戰(zhàn)”。文中的示例代碼講解詳細,對我們學(xué)習(xí)OpenCV有一定的幫助,需要的可以參考一下2022-01-01android studio創(chuàng)建C++項目的實現(xiàn)示例
本文主要介紹了android studio創(chuàng)建C++項目的實現(xiàn)示例,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-06-06