-
Notifications
You must be signed in to change notification settings - Fork 82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature Request: Better Handling Nan and None Values #114
Comments
Hi @Freed-Wu, I am working on the issues. Regarding this one, no idea is coming to me on how to solve it. The function that I use to remove non numerical values litterally removes all of the non numerical values (nan or None).
any idea? |
Take matplotlib as an example: import numpy as np
from matplotlib import pyplot as plt
a = np.arange(10.)
a[2:5] = [np.nan] * 3
plt.plot(a, "b")
plt.show() is equal to import numpy as np
from matplotlib import pyplot as plt
a = np.arange(10.)
a[2:5] = [np.nan] * 3
plt.plot(range(0, 2), a[0:2], "b")
plt.plot(range(5, 10), a[5:10], "b")
plt.show() So. I think just split the array to some parts by import numpy as np
import plotext as plt
a = np.arange(10.)
a[2:5] = [np.nan] * 3
plt.plot(a)
plt.show() |
It's a good idea, but I think it would still produce the same result as in your initial code / post. |
import numpy as np
import plotext as plt
a = np.arange(10.)
a[2:5] = [np.nan] * 3
plt.plot(range(0, 2), a[0:2], color="blue")
plt.plot(range(5, 10), a[5:10], color="blue")
plt.show()
|
If you let matplotlib deal with first code you sent, you get the same result as in
and in
|
This is a slightly different issue, here the problem is the fact that plot() perceives a single signal and so draws lines between each point, while it would be better if it jumps the nan values. I would think about this, but its not trivial.
|
Oh, I am sure. It should be expected behavior of matplotlib.
Right. 😄 It should be an extended version of the first problem: nan exists in the medium of an array, not beginning or end. |
Great!
Aha 😄. I'll ask a problem to matplotlib about is it a bug or an expected behavior. |
Cool thanks a lot for the report. The solution did not involve splitting data luckily (cause otherwise I would have to split all colors, style, and other parameters, which would have been a pain), but the matplotlib example you posted was useful for me to understand anyway. Basically I let nan or None "percolate" inside the calculation until its time to be drawn, where they are simply discarded. I was expecting getting lost in tedious programming, but i got lucky. |
Great! 👍 |
matplotlib/matplotlib#23797 (comment)
It should be the expected behavior of matplotlib. Does plotext support auto-scale? |
No, the new code will not update the x or y limits, it just lets the nan or None value show up to plotting time when they are discarded. The reason why the x limits are preserved at the end is because the x data has all regular values and its limits are calculated naturally.
|
Hi @Freed-Wu , I finally updated The new version is available on GitHib for now and soon also on PyPi. To install follow the indications here. Your changes are documented here and you have been credited here. Any feedback is welcomed. Thanks a lot for your inputs and all the best, |
Expected: A plot which x range is
[0, 200]
, but[0, 40]
don't have any number.Actual: A plot which x range is
[40, 200]
.The text was updated successfully, but these errors were encountered: