Skip to content

Instantly share code, notes, and snippets.

@KenoLeon
Last active May 4, 2022 19:54
Show Gist options
  • Select an option

  • Save KenoLeon/ce8df6bb7d1259fa494d1b0deb4deeed to your computer and use it in GitHub Desktop.

Select an option

Save KenoLeon/ce8df6bb7d1259fa494d1b0deb4deeed to your computer and use it in GitHub Desktop.
Pyplot in the browser with Pyscript
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Pyplot in the Browser</title>
<link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" />
<script defer src="https://pyscript.net/alpha/pyscript.js"></script>
<py-env>
- numpy
- matplotlib
</py-env>
</head>
<body>
<div id="plot"></div>
<py-script output="plot">
import matplotlib.pyplot as plt
import numpy as np
x = np.random.rand(100)
y = np.random.rand(100)
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