Skip to content

Commit 41f737d

Browse files
committed
added live drawing and ploting
1 parent e101d01 commit 41f737d

10 files changed

Lines changed: 5240 additions & 24 deletions

File tree

docs/LiveDraw/livedraw.md

Lines changed: 475 additions & 0 deletions
Large diffs are not rendered by default.

docs/LiveDraw/pythonicDraw_tutorial.md

Lines changed: 563 additions & 0 deletions
Large diffs are not rendered by default.

docs/Media/pythonicMedia_tutorial.md

Lines changed: 447 additions & 0 deletions
Large diffs are not rendered by default.

docs/Plot/plot.md

Lines changed: 515 additions & 0 deletions
Large diffs are not rendered by default.

docs/Print/print.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,72 @@ int main() {
462462

463463
---
464464

465+
## Print Text on Plots (`Figure::print`)
466+
467+
The plotting library includes a `print()` method for adding text annotations directly onto graphs. This is different from the global `print()` function—it's a method on `Figure` objects.
468+
469+
### Basic Usage
470+
471+
```cpp
472+
#include "pythonic/pythonicPlot.hpp"
473+
using namespace pythonic::plot;
474+
475+
Figure fig(80, 24);
476+
477+
// Plot some data
478+
fig.plot([](double x) { return sin(x); }, -PI, PI, "cyan", "sin(x)");
479+
480+
// Add text at data coordinates
481+
fig.print("Maximum", 1.57, 1.0, "yellow"); // Text at (π/2, 1)
482+
fig.print("Minimum", -1.57, -1.0, "red"); // Text at (-π/2, -1)
483+
484+
std::cout << fig.render();
485+
```
486+
487+
### Parameters
488+
489+
| Parameter | Type | Description |
490+
|-----------|------|-------------|
491+
| `text` | `std::string` | The text to display |
492+
| `x` | `double` | X position in **data coordinates** |
493+
| `y` | `double` | Y position in **data coordinates** |
494+
| `color` | `std::string` or `RGBA` | Text color (e.g., `"cyan"`, `"red"`) |
495+
496+
### Pixel Font
497+
498+
Text is rendered using a compact 3×5 pixel Braille font:
499+
500+
- **Numbers**: 0-9
501+
- **Letters**: A-Z, a-z
502+
- **Symbols**: . , : - + = ( ) * / _
503+
504+
### Example: Annotated Graph
505+
506+
```cpp
507+
Figure fig(80, 24);
508+
fig.title("Annotated Sine Wave");
509+
510+
fig.plot([](double x) { return sin(x); }, -PI, PI, "cyan", "sin(x)");
511+
fig.print("Peak", PI/2, 1.0, "green");
512+
fig.print("Zero", 0, 0, "yellow");
513+
fig.print("Trough", -PI/2, -1.0, "red");
514+
515+
std::cout << fig.render();
516+
```
517+
518+
### Method Chaining
519+
520+
```cpp
521+
fig.title("My Plot")
522+
.plot([](double x) { return x*x; }, -3, 3, "cyan", "x²")
523+
.print("Vertex", 0, 0, "yellow")
524+
.print("Rising", 2, 4, "green");
525+
```
526+
527+
See also: [Plot Documentation](../Plot/plot.md)
528+
529+
---
530+
465531
## Performance Considerations
466532
467533
While `print` and `pprint` are convenient for debugging and output, they may not be suitable for performance-sensitive logging. For large `var` objects or containers, consider serializing only the necessary parts to minimize overhead.

include/pythonic/pythonic.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
#include "pythonicError.hpp"
1010
#include "pythonicFastPath.hpp"
1111
#include "pythonicDraw.hpp"
12+
#include "pythonicMedia.hpp"
13+
#include "pythonicLiveDraw.hpp"
14+
#include "pythonicPlot.hpp"
1215
#include "graph_viewer.hpp" // Always include - has internal #ifdef guards
1316

1417
namespace Pythonic
@@ -25,6 +28,8 @@ namespace Pythonic
2528
using namespace pythonic::error;
2629
using namespace pythonic::views;
2730
using namespace pythonic::draw;
31+
using namespace pythonic::media;
32+
using namespace pythonic::plot;
2833
using namespace pythonic::viewer; // Graph viewer (enabled via PYTHONIC_ENABLE_GRAPH_VIEWER)
2934

3035
}

0 commit comments

Comments
 (0)