$ show alandefreitas/matplotplusplus
Matplot++ is a C++ graphics library for data visualization that provides a MATLAB-like API for creating publication-quality plots. It supports a wide range of plot types including line, scatter, bar, histogram, surface, contour, polar, geographic, and 3D plots, as well as image display, graph visualization, and annotations. The library is designed for scientific computing and engineering applications, offering both free-standing function calls and an object-oriented interface with method chaining. It features a pluggable backend architecture with Gnuplot as the primary rendering backend (via pipe communication) and an experimental OpenGL backend. The library handles data transformation, automatic tick calculation, colormap interpolation, contour generation (adapted from Matplotlib), histogram binning with multiple algorithms, and geographic map rendering using bundled Natural Earth data. External dependencies include Gnuplot 5.2.6+ at runtime, with optional support for image processing libraries (CImg, JPEG, TIFF, PNG, OpenCV) and numerical libraries (FFTW, LAPACK, BLAS). The build system is CMake-based with comprehensive options for testing, examples, and documentation generation. Architecturally, the library is organized around a core figure-axes-object hierarchy: figure_type manages the canvas and backend, axes_type holds plot objects and axis configuration, and individual plot types (line, bars, histogram, etc.) inherit from axes_object and implement backend-specific rendering methods. Free-standing functions in freestanding/ forward calls to the current axes via a global figure registry. The backend interface abstracts rendering commands, allowing the same plot objects to work with different backends. The library includes a large set of examples (200+) that serve as both documentation and integration tests, and a documentation pipeline that auto-generates a gallery from example executables. Key entry points for users are the matplot.h header and the free-standing functions (plot, hist, surf, etc.). The library is consumed via CMake's find_package or as a subdirectory. It supports both interactive (reactive) and non-interactive (quiet) modes, and can save plots in multiple formats (SVG, EPS, PNG, PDF, etc.) through backend-specific commands.
The LLM identified 5 files worth highlighting for reuse:
Implements contour line and filled contour generation using a marching-squares algorithm adapted from Matplotlib's QuadContourGenerator. Handles saddle points, corner masking, and chunking for large datasets. Produces contour lines with NaN separators for Gnuplot rendering. Demonstrates non-obvious computational geometry skills and careful handling of edge cases in contour extraction.
Provides comprehensive color handling including named color to RGBA conversion, hex parsing, and a large set of colormap palettes (viridis, plasma, inferno, jet, etc.) implemented as interpolation functions. The color_array type uses an [alpha, r, g, b] convention. Includes utility functions for string representation and gradient generation. The palette namespace contains factory functions that generate colormap arrays with smooth interpolation, demonstrating careful color science and reusable pattern for colormap definition.
Parses compact line specification strings (e.g., '-or' for solid line, circle marker, red color) into structured line style, marker style, and color components. Supports a wide range of line styles, markers, and color abbreviations. The parser handles ambiguous cases and provides a fluent interface for setting properties. This is a self-contained utility that could be extracted for any application needing compact plot style specification.
Defines the abstract interface for rendering backends, including methods for initialization, output configuration, command execution, and drawing primitives (lines, text, images, polygons). The interface supports both command-based backends (like Gnuplot) and direct drawing backends (like OpenGL). This pattern enables the library to support multiple rendering targets without changing plot object code. The interface is clean and minimal, making it a good example of the Strategy pattern for rendering.
Provides a reusable CMake function add_sanitizers that enables compiler sanitizers (Address, Leak, Undefined Behavior, Thread, etc.) for a target, with proper platform detection and flag handling. Includes support for GCC, Clang, and MSVC, and handles linking of sanitizer libraries. This is a standalone CMake module that can be dropped into any C++ project to add sanitizer support with minimal configuration.