olavolav / uniplot

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

Fill area under curve #9

Closed olavolav closed 3 years ago

olavolav commented 3 years ago

This was on the roadmap but have not heard anyone actually request it. So I'll leave the prototypical hack here as an issue in case anyone wants to actually have it.

So in theory we could have an option like y_fill_level that enables filling the are between the points and a given vertical level, usually the zero line.

It might look something like:

plot(ys, title="Sine wave", y_fill_level=-2.5)
                          Sine wave
┌────────────────────────────────────────────────────────────┐
│                                                    ▟█▙     │ 
│                                                   ▗███▌    │ 
│                                       ▗██▖        ▟████    │ 
│                                       ▟███       ▗█████▌   │ 2
│                           ▟█▙        ▗████▌      ▐██████   │ 
│                          ▐███▖       ▟█████      ███████▌  │ 
│              ▗██▖        █████      ▗██████▌    ▐████████  │ 
│              ███▙       ▗█████▖     ▐██████▙    ▟████████▌ │ 
│  ▟█▖        ▐████▖      ▟█████▙     ████████▖  ▗██████████▄│ 1
│ ▐███▖       █████▙      ███████▖   ▗████████▙  ▟███████████│ 
│ ████▙      ▗██████▖    ▐███████▙   ▟█████████▙▟████████████│ 
│▐█████▖     ▐██████▌    █████████▖ ▗████████████████████████│ 
│▟█████▌     ████████   ▗██████████▄█████████████████████████│ 
│███████────▐████████▙──▟████████████████████████████████████│ 0
│███████▌   ██████████▙▟█████████████████████████████████████│ 
│████████  ▐█████████████████████████████████████████████████│ 
│████████▙▄██████████████████████████████████████████████████│ 
└────────────────────────────────────────────────────────────┘
         100       200       300       400       500       600

And then with colors it might look like: Screen Shot 2021-05-01 at 18 18 25

Let me know if this feature would be useful.

olavolav commented 3 years ago

Seems not critical right now, closing