olavolav / uniplot

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

Can it support NaN? #13

Closed Freed-Wu closed 1 year ago

Freed-Wu commented 1 year ago

When ys contain NaN, it will not display.

Thanks.

olavolav commented 1 year ago

@Freed-Wu Thanks for the suggestion! I guess what you would want is that when plotting NaN's are silently dropped, right?

So plot([1,2,3]) should be itentical to plot([1,2,3,np.nan]), right?

Freed-Wu commented 1 year ago

No.

import numpy as np
from matplotlib import pyplot as plt
a = np.arange(10.)
a[2:5] = [np.nan] * 3
plt.plot(a)
plt.show()

a

olavolav commented 1 year ago

Okay got it, I'll look into it. Might be that I'll only get around to the simpler option of the above.

Let me know if you want to have a go at this yourself, and we'll coordinate

Freed-Wu commented 1 year ago

Not sure. I notice another library named plotext has same problem, however, it only ignore NaN (the simpler option of the above). I maybe try to solve https://github.com/piccolomo/plotext/issues/114

olavolav commented 1 year ago

@Freed-Wu It sounds like you have another solution now. In any case I've implemented the simple version we discussed in 0.6.0 and maybe I'll get around to the more sophisticated one eventually.

Thank you for your input!

Freed-Wu commented 1 year ago

You are welcome. :smile:

olavolav commented 1 year ago

This should now work as requested. 😄

>>> import numpy as np
>>> from uniplot import plot
>>> a = np.arange(10.)
>>> a[2:5] = [np.nan] * 3
>>> plot(a, lines=True)
┌────────────────────────────────────────────────────────────┐
│                                                        ▗▄▀▀│ 
│                                                     ▄▞▀▘   │ 8
│                                                 ▗▄▀▀       │ 
│                                              ▄▞▀▘          │ 
│                                          ▗▄▀▀              │ 
│                                       ▄▞▀▘                 │ 
│                                   ▗▄▀▀                     │ 
│                                 ▞▀▘                        │ 
│                                                            │ 
│                                                            │ 4
│                                                            │ 
│                                                            │ 
│                                                            │ 
│                                                            │ 
│                                                            │ 
│   ▗▄▞▀                                                     │ 
│▄▄▀▘▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁│ 0
└────────────────────────────────────────────────────────────┘
           2               5                7              10