-
Notifications
You must be signed in to change notification settings - Fork 80
-
Notifications
You must be signed in to change notification settings - Fork 80
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
2 Feature Requests: Plot Extra Grid Lines and deal with 'None' Values in Data Plot #65
Comments
Hi @NLKNguyen thanks a lot for the issue report. However I find it a bit difficult to understand it. Could you kindly restate in simpler or different terms? in particular, by values, you mean y values (not datetime ones)? if some y values are none/nan, how will this make the plot lines shorter? it seems to me, it would rather remove some of them (the one containing none/nan values) rather then shortening. Thanks for help |
Hi @NLKNguyen, I have read your message and I liked your inputs, including the first one, which I think it is still valid (to plot data which include The horizontal/vertical line feature sounds a little more difficult to implement as I would need to plot a line between the plotting limits, which are only known after the plot is done. Extra complication: there may be double I will update. P.S. you could more simply use |
Hi @NLKNguyen, I think I solved both issues, in the new GitHub 4.1.5 version. Indeed it wasn't straightforward. Here is some code: import pandas as pd
import plotext as plt
plt.datetime.set_datetime_form(date_form='%Y-%m-%d')
t2 = pd.date_range("2022-01-06", periods=5, freq="D")
x2 = [plt.datetime.datetime_to_string(el) for el in t2]
y2 = pd.Series([6,7,8,9,10], index=t2).tolist()
plt.plot_date(x2, y2, marker = "hd", color = 4)
plt.horizontal_line(8.1, color = "red")
plt.vertical_line("2022-01-07", color = "green")
plt.canvas_color(0)
plt.axes_color(0)
plt.ticks_color("bright-yellow")
plt.show() The guide on the functions is here. I haven't properly tested the new feature and functions. If you are available and can double check, I could publish it on PyPi, after some feedback. To install from GitHub: pip install git+https://github.com/piccolomo/plotext Thanks for help and ideas (I have credited you here). |
OMG that's awesome. Great work! I'll surely test it out as soon as possible and let you know. Looks very promising. |
It's very robust!! None/NaN is handled cleanly. Any combination I can think of works well. The horizontal/vertical lines with overlap effect look really nice. Well done! Thank you :) import pandas as pd
import plotext as plt
import numpy as np
plt.datetime.set_datetime_form(date_form='%Y-%m-%d')
t1 = pd.date_range("2022-01-01", periods=5, freq="D")
x1 = [plt.datetime.datetime_to_string(el) for el in t1]
y1 = pd.Series([1,2,None,4,5], index=t1).tolist()
plt.plot_date(x1, y1, marker = "hd", color=1)
t2 = pd.date_range("2022-01-01", periods=10, freq="D")
x2 = [plt.datetime.datetime_to_string(el) for el in t2]
y2 = pd.Series([None, None, np.nan, None, None, 6,7,8,9,10], index=t2).tolist()
plt.plot_date(x2, y2, marker = "hd", color=4)
t3 = pd.date_range("2022-01-01", periods=10, freq="D")
x3 = [plt.datetime.datetime_to_string(el) for el in t3]
y3 = pd.Series([np.nan, np.nan, 4,5,None,7, 8, np.nan,np.nan,np.nan], index=t3).tolist()
plt.plot_date(x3, y3, marker = "hd", color=3)
t4 = pd.date_range("2022-01-01", periods=10, freq="D")
x4 = [plt.datetime.datetime_to_string(el) for el in t4]
y4 = pd.Series([None, 3, 5, 7, None, 3, 4, 5, None, 4], index=t4).tolist()
plt.scatter_date(x4, y4, marker = "hd", color=6)
plt.canvas_color(0)
plt.axes_color(0)
plt.ticks_color("bright-yellow")
plt.horizontal_line(8.1, color = "red")
plt.vertical_line("2022-01-07", color = "green")
plt.horizontal_line(5, color = "blue")
plt.vertical_line("2022-01-09", color = "yellow")
plt.show() |
Glad it worked :-), new 4.1.5 PyPi version also available. Thanks, |
Hi,
The DateTime plot
plot_date
requires all values to be numeric (None/NaN/np.nan is not accepted), but it's useful to be able to display shorter lines that don't span the whole time frame, which requires a way to represent no data like None/NaN. What I'm trying to do is to add some arbitrary trend line/channel on a stock price series.Can you support this?
Thanks!
The text was updated successfully, but these errors were encountered: