Matplotlib Plot mit PyScript
Warten bis der python code durchgerechnet ist.
from pyscript import display
print("python lib werden importiert")#, target = "matplotlib-plot")
import matplotlib.pyplot as plt
print("matplotlib importiert")
import numpy as np
print("numpy importiert")
# Daten generieren
x = np.linspace(0, 2 * np.pi, 400)
y = np.sin(x)
# Plot erstellen
fig, ax = plt.subplots()
ax.plot(x, y, label='sin(x)', color='blue')
ax.set_title('Sinuswelle mit Matplotlib in PyScript')
ax.set_xlabel('X-Achse')
ax.set_ylabel('Y-Achse')
ax.grid(True)
ax.legend()
# Plot im HTML-Element anzeigen
# display() wird von PyScript bereitgestellt, um Python-Objekte im DOM zu rendern
display(fig, target="matplotlib-plot")
Dieses Beispiel zeigt, wie Matplotlib-Diagramme direkt im Browser mit PyScript gerendert werden können.