Skip to content

Instantly share code, notes, and snippets.

@SpiralOutDotEu
Created May 2, 2022 12:16
Show Gist options
  • Save SpiralOutDotEu/344dd29b59b94aeba91aa574b092e535 to your computer and use it in GitHub Desktop.
Save SpiralOutDotEu/344dd29b59b94aeba91aa574b092e535 to your computer and use it in GitHub Desktop.
Python Script Inside HTML
<html>
<head>
<link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" />
<script defer src="https://pyscript.net/alpha/pyscript.min.js"></script>
<py-env>
- numpy
- matplotlib
</py-env>
</head>
<body>
<h1>Let's plot random numbers</h1>
<h3>....wait for plot to appear</h3>
<div id="plot"></div>
<py-script output="plot">
import matplotlib.pyplot as plt
import numpy as np
x = np.random.randn(1000)
y = np.random.randn(1000)
fig, ax = plt.subplots()
ax.scatter(x, y)
fig
</py-script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment