Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented MatPlotLib #359

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions _sources/poc/_static/component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<div>
<iframe
height="1000px"
width="100%"
srcdoc='
<html>
<head>
<title>PyFront - Simple</title>
<meta charset="utf-8" />
<link rel="stylesheet" href="https://pyscript.net/latest/pyscript.css" />
<script defer src="https://pyscript.net/latest/pyscript.js"></script>
<style>
.py-repl-run-button{opacity: 1;}
</style>
</head>
<body>
<py-config>
packages = ["numpy", "pandas", "matplotlib"]
terminal = true
</py-config>

<py-repl> </py-repl>
</body>
</html>'
></iframe>
</div>
50 changes: 50 additions & 0 deletions _sources/poc/matplotlib.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
========================
MatPlotLib Demonstration
========================

This is a demonstartion to show how to use MatPlotLib to create a simple plot.
This plot is implemented in the browser using the PyScript Component I submitted in a previous PR.

.. code:: python

import matplotlib.pyplot as plt
import matplotlib.tri as tri
import numpy as np

# First create the x and y coordinates of the points.
n_angles = 36
n_radii = 8
min_radius = 0.25
radii = np.linspace(min_radius, 0.95, n_radii)

angles = np.linspace(0, 2 * np.pi, n_angles, endpoint=False)
angles = np.repeat(angles[..., np.newaxis], n_radii, axis=1)
angles[:, 1::2] += np.pi / n_angles

x = (radii * np.cos(angles)).flatten()
y = (radii * np.sin(angles)).flatten()
z = (np.cos(radii) * np.cos(3 * angles)).flatten()

# Create the Triangulation; no triangles so Delaunay triangulation created.
triang = tri.Triangulation(x, y)

# Mask off unwanted triangles.
triang.set_mask(np.hypot(x[triang.triangles].mean(axis=1),
y[triang.triangles].mean(axis=1))
< min_radius)

fig1, ax1 = plt.subplots()
ax1.set_aspect('equal')
tpc = ax1.tripcolor(triang, z, shading='flat')
fig1.colorbar(tpc)
ax1.set_title('tripcolor of Delaunay triangulation, flat shading')

display(fig1)

Instructions
------------
Run the code in the notebook below by ``Shift + Enter``.
The plot will be displayed below the code cell.

.. raw:: html
:file: ./_static/component.html
Loading