📈 Graph of y = sin(x)

packages = ["numpy", "matplotlib"] import numpy as np import matplotlib.pyplot as plt from js import document import io import base64 # Generate data x = np.linspace(0, 2 * np.pi, 100) y = np.sin(x) # Plot fig, ax = plt.subplots() ax.plot(x, y, label="y = sin(x)", color='cyan') ax.set_title("Sine Wave") ax.set_xlabel("x") ax.set_ylabel("sin(x)") ax.grid(True) ax.legend() # Save to image buffer buf = io.BytesIO() fig.savefig(buf, format='png') buf.seek(0) img_base64 = base64.b64encode(buf.read()).decode('utf-8') # Display in browser img_html = f'' document.getElementById("plot-output").innerHTML = img_html