olavolav / uniplot

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

Can it support NaN? #13

Closed Freed-Wu closed 2 years ago

Freed-Wu commented 2 years ago

When ys contain NaN, it will not display.

Thanks.

olavolav commented 2 years 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 2 years 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 2 years 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 2 years 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 2 years 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 2 years ago

You are welcome. :smile:

olavolav commented 2 years 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