How to update ui.plot? #55
-
Hello, I'm trying to create an interface where data can be loaded by user selection and plotted. please help I'm desperate from nicegui import ui
import matplotlib.pyplot as plt
data = {'C': 20, 'C++': 15, 'Java': 30,
'Python': 35}
with ui.plot(figsize=(10, 10), close=False) as plot:
ax = plot.fig.add_subplot()
# dig, ax = plt.subplots(figsize=(10, 10))
courses = list(data.keys())
values = list(data.values())
ax.barh(courses, values, color='maroon')
def changeChart():
ax.set_ylabel('abc')
ui.update()
ui.button('Button', on_click=changeChart)
ui.run(host="127.0.0.1", port=8000) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
You need to change two things:
def changeChart():
with plot:
ax.set_ylabel('abc')
ui.update(plot) I have to admit: That's not very intuitive. At least step 2 could be done automatically when leaving the plot context. We might change that in a future release. |
Beta Was this translation helpful? Give feedback.
You need to change two things:
with plot:
context.plot
as an argument toui.update
.I have to admit: That's not very intuitive. At least step 2 could be done automatically when leaving the plot context. We might change that in a future release.