|
c++绘图库matplotlib-cpp的安装与简单使用
https://github.com/lava/matplotlib-cpp
mkdir build && cd build
cmake ..
make
sudo make install
[sudo] jiang 的密码:
[ 6%] Built target spy
[ 12%] Built target nonblock
[ 18%] Built target subplot2grid
[ 25%] Built target modern
[ 31%] Built target surface
[ 37%] Built target basic
[ 43%] Built target animation
[ 50%] Built target fill
[ 56%] Built target xkcd
[ 62%] Built target bar
[ 68%] Built target fill_inbetween
[ 75%] Built target update
[ 81%] Built target contour
[ 87%] Built target minimal
[ 93%] Built target lines3d
[100%] Built target colorbar
Install the project...
-- Install configuration: ""
-- Installing: /usr/local/include/matplotlibcpp.h
-- Installing: /usr/local/lib/matplotlib_cpp/cmake/matplotlib_cppTargets.cmake
-- Installing: /usr/local/lib/matplotlib_cpp/cmake/matplotlib_cppConfig.cmake
安装好后就可以使用了 cmake的方式来
- cmake_minimum_required (VERSION 3.15)
- project (main)
- SET(CMAKE_CXX_STANDARD 14)
- #SET(CMAKE_C_STANDARD 11)
- set(ALL_SRCS "minimal.cpp")
- add_executable(main ${ALL_SRCS})
- # cmake方式依赖Python头文件和库文件的配置
- find_package(Python3 COMPONENTS Interpreter Development REQUIRED)
- find_package(Python3 COMPONENTS NumPy)
- find_package(PythonLibs REQUIRED)
- # python的头文件 PYTHON_INCLUDE_DIRS
- include_directories(${PYTHON_INCLUDE_DIRS})
- # python的库文件 PYTHON_LIBRARIES
- # 解决报错: fatal error: Python.h: 没有那个文件或目录
- target_link_libraries(main ${PYTHON_LIBRARIES})
复制代码
-- Found Python3: /usr/bin/python3.6 (found version "3.6.9") found components: Interpreter Development Development.Module Development.Embed
-- Found Python3: /usr/include/python3.6m (found version "3.6.9") found components: NumPy Interpreter Development.Module
-- Found PythonLibs: /usr/lib/x86_64-linux-gnu/libpython3.6m.so (found version "3.6.9")
- #include "matplotlibcpp.h"
- // 已经安装到了系统里 Installing: /usr/local/include/matplotlibcpp.h
- namespace plt = matplotlibcpp;
- int main() {
- plt::plot({1,3,2,4});
- plt::show();
- return 0;
- }
复制代码
// 图片展示出来 cfar之后的目标点的x和y索引 matplotlib-cpp
plt::figure_size(1280, 960);
plt::title("os_cfar_detected_target_point_num=" + std::to_string(target_point_num_cfar_detected));
plt::xlabel("x_zhou");
plt::ylabel("y_zhou");
std::vector<float> plot_x, plot_y;
for(auto iter=target_point_cfar_detected.begin(); iter != target_point_cfar_detected.end(); ++iter){
point_3d temp = *iter;
plot_x.push_back(ticks_x_axis[int(temp.get_x())]);
plot_y.push_back(ticks_y_axis[int(temp.get_y())]);
}
std::map<std::string, std::string> param_dict;
param_dict["marker"] = "*";
param_dict["c"] = "red";
plt::scatter<float, float>(plot_x, plot_y, 10.0, param_dict);
plt::xticks<float>(ticks_x_axis);
plt::yticks<float>(ticks_y_axis);
plt::save("os_cfar_detected_target_point_num_" + std::to_string(target_point_num_cfar_detected) + ".png");
plt::show();
|
|