介绍:
- matplotlib-cpp:C++ ploting library
简单使用:
1. minimal example:
#include "matplotlibcpp.h"
namespace plt = matplotlibcpp;
int main()
{
plt::plot({1,3,2,4});
plt::show();
}
2. g++ 编译
g++ minimal.cpp -I/usr/include/pyhon3.8 -lpython3.8
3. cmake
target_include_directories(${PROJECT_NAME} PRIVATE ${Python3_INCLUDE_DIRS} ${Python3_NumPy_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} INTERFACE
Python3::Module
Python3::NumPy
)
target_link_libraries(${PROJECT_NAME} PRIVATE ${Python3_LIBRARIES})
问题:
- warning: /python3/dist-packages/gi/module.py:171: Warning:g_once_init_leave: assertion ‘result != 0’ failed
解决:
- the matplotlib backend that use gtk+3 while cv2.show() use gtk2.x to process
- 只使用matplot可视化,不使用imshow
1. plot y versus x.
#include <vector>
#include "matplotlibcpp.h"
namespace plt = matplotlibcpp;
int main() {
std::vector<double> x = {1, 2, 3, 4};
std::vector<double> y = {1, 4, 9, 16};
plt::plot(x, y);
plt::show();
return 0;
}
g++ test1.cpp -std=c++11 -I/usr/include/python3.8 -I/home/xx/.local/lib/python3.8/site-packages/numpy/core/include -lpython3.8
![xy](https://img-blog.csdnimg.cn/cc61314c676e4ba0b85de982a0670081.png#pic_center)
2. 多个函数
3. the style of a line
4.