How to change the number of traces in ui.line_plot during runtime #3927
Unanswered
keenanjohnson
asked this question in
Q&A
Replies: 1 comment
-
Hi @keenanjohnson, Changing the number of lines is currently not supported. But as a workaround, you can fill lines with NaN values to hide them: line_plot = ui.line_plot(n=2, limit=20).with_legend(['sin', 'cos'], loc='upper center', ncol=2)
# monkey patch to set ylim to -1, 1
set_ylim = line_plot.fig.gca().set_ylim
line_plot.fig.gca().set_ylim = lambda *_: set_ylim(-1, 1)
def update_line_plot() -> None:
now = datetime.now()
x = now.timestamp()
y1 = math.sin(x) if sin.value else np.nan
y2 = math.cos(x) if cos.value else np.nan
line_plot.push([now], [[y1], [y2]])
ui.timer(0.1, update_line_plot)
sin = ui.checkbox('sin', value=True)
cos = ui.checkbox('cos', value=True) Note that we need to monkey-patch the |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Question
I have an application where I would like to change the number of fraces in a ui.line_plot. What's the best way to accomplish this in nicegui as the n argument comes in during object construction.
https://nicegui.io/documentation/line_plot
I am trying to build an application where one out of six channels can be selected to be enabled or not on a plot. This would require changing the number of plotted channels
Beta Was this translation helpful? Give feedback.
All reactions