olavolav / uniplot

Lightweight plotting to the terminal. 4x resolution via Unicode.
MIT License
370 stars 16 forks source link

Feature request: Add editable data in plots #34

Open PabloRuizCuevas opened 3 months ago

PabloRuizCuevas commented 3 months ago

The objective of this proposal is being able to redraw the plot without changing axis labels etc.

There are several ways of adding this feature, the one used in matplotlib is using an instance of a class, but as first draft I developed a simple generator that is able to do the same:

https://github.com/PabloRuizCuevas/uniplot/blob/master/uniplot/uniplot.py

    from uniplot import plot_gen
    plot_g = plot_gen(
        **{
            "lines": [True, True],
            "width": 180,
            "x_unit": "$",
            "y_unit": "$",
            "color": ["green", "red"],
        }
    )
    next(plot_g)
    args = {}
    plot_g.send(([1,2,3], [4,3,2], args)) # pass only data that changes.
    # the plot is plotted
    plot_g.send(([1,2,3], [2,3,2], args))
    # the plot is modified

With this structure we avoid creating a class for the plot, though it may be desirable to do so, I could also make a draft of that if you like it more.