Matplot++ Documentation

repository·master·Indexed 26 days ago

https://github.com/alandefreitas/matplotplusplus

A C++ graphics library for scientific data visualization providing interactive plotting and high-quality export formats. It features a compact syntax and supports a wide range of plot types, including 2D and 3D line plots, scatter plots, histograms, boxplots, polar plots, heatmaps, and geography-based plots (geoplot, geoscatter, geobubble). The library supports generic backends, including an experimental OpenGL backend, and requires Gnuplot 5.2.6+ as a runtime dependency.

Tokens
18.1K
Snippets
95
Records
265
Agent score
89%

What's inside Matplot++

  1. Overview of Matplot++

    master

    Matplot++ is a C++ graphics library designed for scientific data visualization. It provides interactive plotting, high-quality export formats for scientific publications, and a compact syntax similar to other popular plotting libraries. Key features include:

    • Dozens of plot categories with specialized algorithms.
    • Multiple coding styles (e.g., member functions vs. free-standing functions).
    • Support for generic backends.
    • Interactive plotting capabilities.
    • Support for various plot types including line plots, discrete data, polar plots, contour plots, surfaces, and more.
  2. Compare Matplot++ interfaces with Matplotlib and Matlab

    master

    Matplot++ is designed with an interface similar to Matplotlib and Matlab to ease the transition for users. While the internal structures differ, the function names are chosen for convenience to match these established libraries.

    Key Differences & Scope:

    • Plot Categories: Matplot++ covers almost all plot categories found in Matplotlib and Matlab.
    • Specialized Toolboxes: Unlike Matlab, Matplot++ does not include domain-specific toolboxes (e.g., for specialized scientific computing).
    • Network Plots: Matplot++ does not currently have a dedicated special plot category for networks (in Python, this is typically handled by NetworkX).
  3. Understand Matplot++ backends and Gnuplot dependency

    master

    Matplot++ uses Gnuplot as its default backend via process pipes. This allows for both interactive and non-interactive modes and provides cross-platform abstraction.

    Key considerations when using the Gnuplot backend:

    • Responsiveness: Because parameters are passed from the figure object rather than the interactive window, plots may be less responsive to manual window resizing. It is recommended to programmatically set the window size on the figure object for consistent results.
    • Word Clouds: Word clouds are sensitive to the backend. For best results, save word clouds non-programmatically (using the interactive window widget) rather than via the save function.
    • 3D Plots: Interactive features like rotating 3D plots may not work well when using subplots.
    • Extensibility: The library is designed with a backend interface that allows advanced users to implement alternative backends (e.g., OpenGL or Dear ImGui style) to overcome Gnuplot's pipe-based limitations.
  4. Understand the Matplot++ Object Hierarchy

    master

    Matplot++ uses a hierarchical object-oriented structure for data visualization:

    1. figure: The top-level object representing a window or an image file. It connects to a backend for rendering or exporting.
    2. axes: Contained within a figure. An axes object holds a collection of plot primitives (like lines, markers, etc.). A figure can have multiple axes objects (subplots).
    3. axis: Contained within an axes object. These represent specific coordinates (e.g., $x$, $y$, $z$ for 3D plots; $r$, $t$ for polar plots; $cb$ for colorbars).
    4. legend: An object associated with an axes to manage labels and the display box.

    By default, figures are in reactive mode, meaning updating a property of a child object automatically triggers a redraw. In quiet mode (non-reactive), you must manually call draw() to update the display.

  5. Format X, Y, and Z axis ticks

    master

    You can customize the appearance of axis tick labels using tick format functions. Matplot++ provides specific methods for X, Y, and Z axes to control how values are displayed (e.g., scientific notation, currency, or custom string formats).

    Refer to the following example files for specific implementation details:

    • X Tick Format: examples/appearance/grid/xtickformat/xtickformat_2.cpp
    • Y Tick Format: examples/appearance/grid/ytickformat/ytickformat_1.cpp
    • Z Tick Format: examples/appearance/grid/ztickformat/ztickformat_1.cpp
  6. Apply Colormaps and Color Bars

    master

    For heatmaps or 3D plots, you can apply colormaps to represent data values through color. You can also display a color bar to provide a scale for these colors.

    • Colormaps: Apply color schemes to data. See examples/appearance/colormaps/colormap/colormap_1.cpp.
    • Color Bar: Add a visual legend for color scales. See examples/appearance/colormaps/colorbar/colorbar_1.cpp.