东方耀AI技术分享

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
热搜: 活动 交友 discuz
查看: 2418|回复: 0
打印 上一主题 下一主题

[C/C++] c++绘图库matplotlib-cpp的安装与简单使用

[复制链接]

1365

主题

1856

帖子

1万

积分

管理员

Rank: 10Rank: 10Rank: 10

积分
14449
QQ
跳转到指定楼层
楼主
发表于 2021-12-1 11:45:53 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式


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的方式来






  1. cmake_minimum_required (VERSION 3.15)
  2. project (main)

  3. SET(CMAKE_CXX_STANDARD 14)
  4. #SET(CMAKE_C_STANDARD 11)


  5. set(ALL_SRCS "minimal.cpp")

  6. add_executable(main ${ALL_SRCS})

  7. # cmake方式依赖Python头文件和库文件的配置

  8. find_package(Python3 COMPONENTS Interpreter Development REQUIRED)
  9. find_package(Python3 COMPONENTS NumPy)
  10. find_package(PythonLibs REQUIRED)

  11. # python的头文件 PYTHON_INCLUDE_DIRS
  12. include_directories(${PYTHON_INCLUDE_DIRS})
  13. # python的库文件 PYTHON_LIBRARIES   
  14. # 解决报错: fatal error: Python.h: 没有那个文件或目录
  15. 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")




  1. #include "matplotlibcpp.h"

  2. // 已经安装到了系统里 Installing: /usr/local/include/matplotlibcpp.h

  3. namespace plt = matplotlibcpp;

  4. int main() {
  5.     plt::plot({1,3,2,4});
  6.     plt::show();
  7.     return 0;
  8. }
复制代码



// 图片展示出来 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();





















minimal.png (19.7 KB, 下载次数: 91)

minimal.png

os_cfar_detected_target_point_num_1138.png (107.24 KB, 下载次数: 90)

os_cfar_detected_target_point_num_1138.png
让天下人人学会人工智能!人工智能的前景一片大好!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|人工智能工程师的摇篮 ( 湘ICP备2020019608号-1 )

GMT+8, 2024-6-16 07:32 , Processed in 0.197460 second(s), 21 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表