Skip to content
Discussion options

You must be logged in to vote

Hi @LeoM1970,

Here is an example on how to update ui.matplotlib:

x = np.linspace(0.0, 5.0)
y = np.cos(2 * np.pi * x) * np.exp(-x)

with ui.matplotlib(figsize=(3, 2)).figure as fig:
    fig.gca().plot(x, y, '-')

def update():
    with fig:
        fig.gca().plot(x, y + 1, ':')

ui.button('Update', on_click=update)

The key is to enter the fig context once again. When leaving this context, the UI element is updated automatically.

Alternatively you can call plot.update(), but then you need to keep a reference to plot, e.g. like this:

x = np.linspace(0.0, 5.0)
y = np.cos(2 * np.pi * x) * np.exp(-x)

plot = ui.matplotlib(figsize=(3, 2))
with plot.figure as fig:
    fig.gca().plot(x, y, '-')

def 

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by LeoM1970
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants