olavolav/uniplot

Requesting Support for Plotting Line Graphs

Opened this issue ยท 6 comments

Hi Olav. Appreciate the great work with this project. Found this quite useful in logging some data graphically to the terminal in a few of my Data Science projects.
Here is a recommendation for a new feature that can be added. I understand that there is currently support for plotting Scatter Plots and Histograms in Uniplot. Would be great if support for plotting Line Graphs was also added to visualize the trend of data. Kindly look into the possibility of doing this.
Thanks.

Hi @gourisariah thanks for the feedback! Happy to hear that uniplot was helpful ๐Ÿ˜„

There is limited line drawing support in uniplot already by using the lines option, were you aware of that?

For example:

>>> from uniplot import plot
>>> plot([1,3,2], lines=True)
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                            โ–—โ–€โ–€โ–šโ–„โ––                          โ”‚ 3
โ”‚                          โ–—โ–žโ–˜    โ–โ–€โ–„โ–„                       โ”‚ 
โ”‚                        โ–—โ–žโ–˜          โ–€โ–€โ–„โ––                   โ”‚ 
โ”‚                       โ–„โ–˜               โ–โ–€โ–šโ–„                โ”‚ 
โ”‚                     โ–„โ–€                     โ–€โ–€โ–„โ––            โ”‚ 
โ”‚                   โ–—โ–ž                          โ–โ–€โ–šโ–„         โ”‚ 
โ”‚                 โ–—โ–žโ–˜                               โ–€โ–€โ–„โ––     โ”‚ 
โ”‚                โ–„โ–˜                                    โ–โ–€โ–šโ–„  โ”‚ 
โ”‚              โ–„โ–€                                          โ–€โ–€โ”‚ 2
โ”‚            โ–—โ–ž                                              โ”‚ 
โ”‚          โ–—โ–žโ–˜                                               โ”‚ 
โ”‚         โ–žโ–˜                                                 โ”‚ 
โ”‚       โ–„โ–€                                                   โ”‚ 
โ”‚     โ–—โ–€                                                     โ”‚ 
โ”‚   โ–—โ–žโ–˜                                                      โ”‚ 
โ”‚  โ–žโ–˜                                                        โ”‚ 
โ”‚โ–„โ–€                                                          โ”‚ 1
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
 1                             2                            3

For displaying trends I suppose you would need the possibility to draw points and then a line on top, right? That would indeed not be possible currently, but wouldn't be difficult to add

Hi @olavolav. I was not aware of the line drawing support using the line argument. However, what I am precisely looking for is the ability to draw points and then join them using lines, as you have clearly understood. Would be amazing if this feature was added. Thanks.

Okay, so one way to do that would be to allow for a list to be passed to the lines option.

So you would write for example:

import numpy as np
import random

# Let's say that these are your measurement points with some noise on top
xs_scatter = np.arange(0, 100)
ys_scatter = 0.5*xs_scatter + (random.random() - 0.5)

# This is your trend
xs_trend = [-10,110]
ys_trend = [-5, 55]

plot(xs=[xs_scatter, xs_trend], ys=[ys_scatter, ys_trend], lines=[False, True], legend_labels=["data points", "trend line"])

The lines=[False, True] part would make the first series drawn as points, and the second one as a line.

Here I am supplying x coordinates for both since right now you can only supply none or all x coordinates.

@gourisariah Would that flexibility in the lines option help you for your use case?

Yes @olavolav. That should work. I guess, for simplicity sake, you can also probably define a function as follows so that code for plotting a line graph is simpler to understand.

def line_graph(ys: Any, xs: Optional[Any] = None, **kwargs) -> None:
    plot(ys=[ys, ys], xs=[xs, xs], lines=[True, False], **kwargs)
    return

What do you think?

Thanks @gourisariah for your input! I am somewhat hesitant to expand the API too much at this point, first want to see more where on the scale simplicity-versus-flexibility the users mostly are. But I'll keep your function in mind!

In the meantime, I have a prototype of the feature itself:

Bildschirmfoto 2021-04-07 um 10 45 35

Will clean it up and publish it soon, most likely tonight or tomorrow.

Thanks again for your input!

Sure @olavolav. Thanks a lot!!