My notebook does not show the matplotlib
My notebook does not show the matplotlib.pyplot graphs in app view, but they work fine in edit mode. What can I do?
5 Replies
hi @krigar_b can you paste a minimal example of your code?
@app.cell
def (mo):
userprhour = mo.ui.slider(start=0, stop=10000000, step=500000, label="users per hour")
sigma = mo.ui.slider(start=1, stop=6, step=0.5, label="sigma")
[userprhour, sigma]
return sigma, userprhour
@app.cell
def (np, plt, sigma):
# Parameters for the Gaussian distribution
mean = 300
std_deviation = np.sqrt(300)
# Generating points on the x axis between -4 and 4
x = np.linspace(0, 1000, 1000)
# Calculating the Gaussian distribution values for each x
y = (1 / (np.sqrt(2 * np.pi) * std_deviation)) * np.exp(
-0.5 * ((x - mean) / std_deviation) ** 2
)
# Creating the plot
plt.figure(figsize=(8, 6))
plt.plot(x, y, label="Gaussian Distribution\nMean = 0, Std Dev = 1")
plt.vlines(
300 + np.sqrt(300) * sigma.value, 0, 0.02, colors="k", linestyles="solid"
)
plt.title("Gaussian Distribution")
plt.xlabel("x")
plt.ylabel("Probability Density")
plt.legend()
plt.grid(True)
plt.show()
return mean, std_deviation, x, y
@app.cell
def (factorial, np, plt):
t = np.arange(0, 100, 0.1)
d = np.exp(-10)*np.power(10, t)/factorial(t)
plt.plot(t, d)
plt.show()
return d, t
@app.cell
def ():
import marimo as mo
from scipy.special import factorial
import numpy as np
import matplotlib.pyplot as plt
return factorial, mo, np, plt
if name == "main":
app.run()
The top cell shows up in app view - the rest don't
Hi! plt.show() prints to the console area (for debugging), and doesn’t show up as a cell (app) output. If you replace plt.show() with plt.gca() it should work!
For more info run
marimo tutorial plots
in your terminal
Thank you so much!
You’re welcome! Thanks for asking!