wPlot2D version: 0.1.1
A lightweight C++ library for clear and customizable 2D scientific plots.
Loading...
Searching...
No Matches
wPlot2D - ECS-Based 2D Plotting Engine

wPlot2D

Introduction

wPlot2D is a lightweight C++ plotting library designed to create clean and customizable 2D visualizations. It provides essential features such as axes, labels, titles, legends, and annotations, while allowing users to export high-quality graphics for reports, teaching, or research. The library is built with a modular design, making it easy to integrate into existing C++ projects. Its focus is on clarity, precision, and reproducibility, providing an accessible tool for academic and scientific work.

Features

  • Entity and Component system
  • Dynamic component management with type-safe access
  • Support for SFML-based rendering

example

#include <wPlot2D.hpp>
#include <cmath>
int main( )
{
// --- Graph creation ------------------------------------------------------
auto graph = wPlot2D::GraphicsEntity( );
graph.setOrigin( { 0.5f, 0.5f } );
graph.setScale( { 0.1f, 0.1f } );
// --- Graph title ---------------------------------------------------------
auto title = graph.addTitle( "wPlot2D", wPlot2D::TitleAlignment::Top );
title->setFont( graph.getFont( "Inconsolata" ) );
title->setFrameThickness( 5.0f );
title->setPadding( { 20.0f, 20.0f } );
// --- X axis --------------------------------------------------------------
auto xAxis = graph.addAxis( wPlot2D::AxisType::X_AXIS, { -3.8f, 3.8f } );
xAxis->addTitle( "x" );
xAxis->addNotches( 0.5f, wPlot2D::NotchPosition::Center, true );
// --- Y axis --------------------------------------------------------------
auto yAxis = graph.addAxis( wPlot2D::AxisType::Y_AXIS, { -3.8f, 3.8f } );
yAxis->addTitle( "f(x)" );
yAxis->addNotches( 0.5f, wPlot2D::NotchPosition::Center, true );
// --- Function (sinus) ----------------------------------------------------
auto fSinus = graph.addFunction( [ ](double x ) { return std::sin( x ); }, -3.3, 3.3 );
fSinus->setColor( sf::Color::Red );
// --- Legend --------------------------------------------------------------
auto legend = graph.addLegend( { 0.2f, 0.8f }, true );
legend->addItem( "Sinus", fSinus );
legend->setCharacterSize( 30.0f );
legend->setFont( graph.getFont( "Courier" ) );
// --- Save the graph ------------------------------------------------------
graph.saveToFile( "/../output/Example.png" );
return 0;
}
Central entity responsible for graphical rendering in wPlot2D.
Definition wGraphicsEntity.hpp:65
int main()
Definition main.cpp:84
@ X_AXIS
Definition wAxisEntity.hpp:36
@ Y_AXIS
Definition wAxisEntity.hpp:37
@ Top
Definition wGraphicsEntity.hpp:38
@ Center
Definition wAxisEntity.hpp:46
Main public include file for the wPlot2D library.

Links

Author

Created by Wilfried Koch.
Copyright @ 2025 Wilfried Koch. All rights reserved.