marimo
marimo copied to clipboard
Plot blinking: matplotlib interactive
Describe the bug
I suspect that's very much the same as #251, but maybe not for mpl.interactive?
Besides blinking, mpl.interactive will also use a new port every time I drag the slider, and stop responding after a few changes.
Version
0.1.38
Code to reproduce
import marimo
__generated_with = "0.1.38"
app = marimo.App()
@app.cell
def __(exp):
exp
return
@app.cell
def __(altp, exp, mo, mplplot, plotlyplot, snsplot):
mo.vstack(
[
mo.md(f"$$y=x^{exp.value}$$"),
mo.tabs(
{
"altair": mo.vstack([altp, altp.value]),
"plotly": plotlyplot(exp.value),
"seaborn": snsplot(exp.value),
"matplotlib": mplplot(exp.value),
}
),
]
)
return
@app.cell
def __():
import marimo as mo
from plotly import express as px
import altair as alt
import numpy as np
import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
from functools import cache
return alt, cache, mo, np, pd, plt, px, sns
@app.cell
def __(mo):
exp = mo.ui.slider(1, 8, 1, label="exp: ")
return exp,
@app.cell
def __(cache, np):
@cache
def prep_xy(exp):
x = np.linspace(0, 5, 100)
return x, x**exp
return prep_xy,
@app.cell
def __(alt, cache, mo, pd, prep_xy):
@cache
def altplot(exp):
x, y = prep_xy(exp)
data = pd.DataFrame({"x": x, "y": y})
return mo.ui.altair_chart(
alt.Chart(data).mark_line().encode(x="x", y="y"),
chart_selection="interval",
)
return altplot,
@app.cell
def __(cache, prep_xy, px):
@cache
def plotlyplot(exp):
x, y = prep_xy(exp)
return px.line(x=x, y=y)
return plotlyplot,
@app.cell
def __(cache, prep_xy, sns):
@cache
def snsplot(exp):
x, y = prep_xy(exp)
return sns.lineplot(x=x, y=y)
return snsplot,
@app.cell
def __(cache, mo, plt, prep_xy):
@cache
def mplplot(exp):
x, y = prep_xy(exp)
plt.plot(x, y)
return mo.mpl.interactive(plt.gcf())
return mplplot,
@app.cell
def __(altplot, exp):
altp = altplot(exp.value)
return altp,
if __name__ == "__main__":
app.run()
Yes the plot blinking is the same as #251. We fixed it for mo.ui.altair_chart but not for vanilla altair or plotly. Thanks for opening this issue to track.
Besides blinking, mpl.interactive will also use a new port every time I drag the slider, and stop responding after a few changes.
Oops! Will look into it. Thanks for the repro.
from the code above, only seaborn is working
from the code above, only seaborn is working
@JVSigaud , what do you mean? Do none of the other plots show up?
The examples work for me. What browser / browser version are you using?
I'm using the chrome version 118.0.5993.118. None of the other plots show up. I also tried in the vscode's extension and did not work either. Im using marimo version 0.1.39.
Thanks @JVSigaud . I opened #273, let's move the discussion there