mirror of https://github.com/pyodide/pyodide.git
Fix the _tri and _qhull modules in matplotlib
This commit is contained in:
parent
732ca50b13
commit
5f8bd963b7
|
@ -24,7 +24,7 @@ URL=https://files.pythonhosted.org/packages/ec/ed/46b835da53b7ed05bd4c6cae293f13
|
|||
CC=emcc
|
||||
CXX=em++
|
||||
AR=emar
|
||||
CFLAGS=-Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I$(HOSTSRC) -I../numpy/host/numpy-$(NPYVERSION)/numpy/core/include -I../numpy/config -I../numpy/host/numpy-$(NPYVERSION)/build/src.$(PLATFORMSLUG)/numpy/core/include/numpy -I$(PYTHONINCLUDE) -Wno-unused-function -s USE_FREETYPE=1 -s USE_LIBPNG=1 -s USE_ZLIB=1 -I$(AGGINC) -I$(HOSTDIR)/extern -I$(HOSTDIR) -DMPL_DEVNULL=/dev/null
|
||||
CFLAGS=-Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I$(HOSTSRC) -I../numpy/host/numpy-$(NPYVERSION)/numpy/core/include -I../numpy/config -I../numpy/host/numpy-$(NPYVERSION)/build/src.$(PLATFORMSLUG)/numpy/core/include/numpy -I$(PYTHONINCLUDE) -Wno-unused-function -s USE_FREETYPE=1 -s USE_LIBPNG=1 -s USE_ZLIB=1 -I$(AGGINC) -I$(HOSTDIR)/extern -I$(HOSTDIR) -DMPL_DEVNULL=/dev/null -D__STDC_FORMAT_MACROS=1 -DNPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION
|
||||
|
||||
|
||||
OBJECTS= \
|
||||
|
@ -35,7 +35,8 @@ OBJECTS= \
|
|||
$(BUILD)/_path.so \
|
||||
$(BUILD)/_contour.so \
|
||||
$(BUILD)/backends/_backend_agg.so \
|
||||
$(BUILD)/_tri.so
|
||||
$(BUILD)/_tri.so \
|
||||
$(BUILD)/_qhull.so
|
||||
|
||||
|
||||
AGGOBJECTS = \
|
||||
|
@ -165,7 +166,7 @@ $(BUILD)/_qhull.so: \
|
|||
$(QHULLSRC)/usermem.bc \
|
||||
$(QHULLSRC)/userprintf.bc \
|
||||
$(QHULLSRC)/userprintf_rbox.bc
|
||||
$(CC) $(SIDE_LDFLAGS) $^ -o $@.wasm
|
||||
$(CC) $(SIDE_LDFLAGS) -lm $^ -o $@.wasm
|
||||
mv $@.wasm $@
|
||||
|
||||
|
||||
|
|
|
@ -1,213 +0,0 @@
|
|||
diff -ur matplotlib-2.2.2/lib/matplotlib/axes/_axes.py matplotlib-2.2.2/lib/matplotlib/axes/_axes.py
|
||||
--- a/lib/matplotlib/axes/_axes.py 2018-03-17 14:03:23.000000000 -0400
|
||||
+++ b/lib/matplotlib/axes/_axes.py 2018-05-17 09:42:02.998583676 -0400
|
||||
@@ -37,7 +37,7 @@
|
||||
import matplotlib.text as mtext
|
||||
import matplotlib.ticker as mticker
|
||||
import matplotlib.transforms as mtransforms
|
||||
-import matplotlib.tri as mtri
|
||||
+# import matplotlib.tri as mtri
|
||||
from matplotlib.cbook import (
|
||||
_backports, mplDeprecation, warn_deprecated,
|
||||
STEP_LOOKUP_MAP, iterable, safe_first_element)
|
||||
@@ -8017,18 +8017,18 @@
|
||||
|
||||
return artists
|
||||
|
||||
- def tricontour(self, *args, **kwargs):
|
||||
- return mtri.tricontour(self, *args, **kwargs)
|
||||
- tricontour.__doc__ = mtri.tricontour.__doc__
|
||||
-
|
||||
- def tricontourf(self, *args, **kwargs):
|
||||
- return mtri.tricontourf(self, *args, **kwargs)
|
||||
- tricontourf.__doc__ = mtri.tricontour.__doc__
|
||||
-
|
||||
- def tripcolor(self, *args, **kwargs):
|
||||
- return mtri.tripcolor(self, *args, **kwargs)
|
||||
- tripcolor.__doc__ = mtri.tripcolor.__doc__
|
||||
-
|
||||
- def triplot(self, *args, **kwargs):
|
||||
- return mtri.triplot(self, *args, **kwargs)
|
||||
- triplot.__doc__ = mtri.triplot.__doc__
|
||||
+ # def tricontour(self, *args, **kwargs):
|
||||
+ # return mtri.tricontour(self, *args, **kwargs)
|
||||
+ # tricontour.__doc__ = mtri.tricontour.__doc__
|
||||
+
|
||||
+ # def tricontourf(self, *args, **kwargs):
|
||||
+ # return mtri.tricontourf(self, *args, **kwargs)
|
||||
+ # tricontourf.__doc__ = mtri.tricontour.__doc__
|
||||
+
|
||||
+ # def tripcolor(self, *args, **kwargs):
|
||||
+ # return mtri.tripcolor(self, *args, **kwargs)
|
||||
+ # tripcolor.__doc__ = mtri.tripcolor.__doc__
|
||||
+
|
||||
+ # def triplot(self, *args, **kwargs):
|
||||
+ # return mtri.triplot(self, *args, **kwargs)
|
||||
+ # triplot.__doc__ = mtri.triplot.__doc__
|
||||
diff -ur matplotlib-2.2.2/lib/matplotlib/pyplot.py host/matplotlib-2.2.2/lib/matplotlib/pyplot.py
|
||||
--- matplotlib-2.2.2/lib/matplotlib/pyplot.py 2018-03-17 14:03:23.000000000 -0400
|
||||
+++ host/matplotlib-2.2.2/lib/matplotlib/pyplot.py 2018-05-17 09:45:27.193765098 -0400
|
||||
@@ -3630,85 +3630,85 @@
|
||||
sci(ret.lines)
|
||||
return ret
|
||||
|
||||
-# Autogenerated by boilerplate.py. Do not edit as changes will be lost.
|
||||
-@_autogen_docstring(Axes.tricontour)
|
||||
-def tricontour(*args, **kwargs):
|
||||
- ax = gca()
|
||||
- # Deprecated: allow callers to override the hold state
|
||||
- # by passing hold=True|False
|
||||
- washold = ax._hold
|
||||
- hold = kwargs.pop('hold', None)
|
||||
- if hold is not None:
|
||||
- ax._hold = hold
|
||||
- from matplotlib.cbook import mplDeprecation
|
||||
- warnings.warn("The 'hold' keyword argument is deprecated since 2.0.",
|
||||
- mplDeprecation)
|
||||
- try:
|
||||
- ret = ax.tricontour(*args, **kwargs)
|
||||
- finally:
|
||||
- ax._hold = washold
|
||||
- if ret._A is not None: sci(ret)
|
||||
- return ret
|
||||
-
|
||||
-# Autogenerated by boilerplate.py. Do not edit as changes will be lost.
|
||||
-@_autogen_docstring(Axes.tricontourf)
|
||||
-def tricontourf(*args, **kwargs):
|
||||
- ax = gca()
|
||||
- # Deprecated: allow callers to override the hold state
|
||||
- # by passing hold=True|False
|
||||
- washold = ax._hold
|
||||
- hold = kwargs.pop('hold', None)
|
||||
- if hold is not None:
|
||||
- ax._hold = hold
|
||||
- from matplotlib.cbook import mplDeprecation
|
||||
- warnings.warn("The 'hold' keyword argument is deprecated since 2.0.",
|
||||
- mplDeprecation)
|
||||
- try:
|
||||
- ret = ax.tricontourf(*args, **kwargs)
|
||||
- finally:
|
||||
- ax._hold = washold
|
||||
- if ret._A is not None: sci(ret)
|
||||
- return ret
|
||||
+# # Autogenerated by boilerplate.py. Do not edit as changes will be lost.
|
||||
+# @_autogen_docstring(Axes.tricontour)
|
||||
+# def tricontour(*args, **kwargs):
|
||||
+# ax = gca()
|
||||
+# # Deprecated: allow callers to override the hold state
|
||||
+# # by passing hold=True|False
|
||||
+# washold = ax._hold
|
||||
+# hold = kwargs.pop('hold', None)
|
||||
+# if hold is not None:
|
||||
+# ax._hold = hold
|
||||
+# from matplotlib.cbook import mplDeprecation
|
||||
+# warnings.warn("The 'hold' keyword argument is deprecated since 2.0.",
|
||||
+# mplDeprecation)
|
||||
+# try:
|
||||
+# ret = ax.tricontour(*args, **kwargs)
|
||||
+# finally:
|
||||
+# ax._hold = washold
|
||||
+# if ret._A is not None: sci(ret)
|
||||
+# return ret
|
||||
+
|
||||
+# # Autogenerated by boilerplate.py. Do not edit as changes will be lost.
|
||||
+# @_autogen_docstring(Axes.tricontourf)
|
||||
+# def tricontourf(*args, **kwargs):
|
||||
+# ax = gca()
|
||||
+# # Deprecated: allow callers to override the hold state
|
||||
+# # by passing hold=True|False
|
||||
+# washold = ax._hold
|
||||
+# hold = kwargs.pop('hold', None)
|
||||
+# if hold is not None:
|
||||
+# ax._hold = hold
|
||||
+# from matplotlib.cbook import mplDeprecation
|
||||
+# warnings.warn("The 'hold' keyword argument is deprecated since 2.0.",
|
||||
+# mplDeprecation)
|
||||
+# try:
|
||||
+# ret = ax.tricontourf(*args, **kwargs)
|
||||
+# finally:
|
||||
+# ax._hold = washold
|
||||
+# if ret._A is not None: sci(ret)
|
||||
+# return ret
|
||||
+
|
||||
+# # Autogenerated by boilerplate.py. Do not edit as changes will be lost.
|
||||
+# @_autogen_docstring(Axes.tripcolor)
|
||||
+# def tripcolor(*args, **kwargs):
|
||||
+# ax = gca()
|
||||
+# # Deprecated: allow callers to override the hold state
|
||||
+# # by passing hold=True|False
|
||||
+# washold = ax._hold
|
||||
+# hold = kwargs.pop('hold', None)
|
||||
+# if hold is not None:
|
||||
+# ax._hold = hold
|
||||
+# from matplotlib.cbook import mplDeprecation
|
||||
+# warnings.warn("The 'hold' keyword argument is deprecated since 2.0.",
|
||||
+# mplDeprecation)
|
||||
+# try:
|
||||
+# ret = ax.tripcolor(*args, **kwargs)
|
||||
+# finally:
|
||||
+# ax._hold = washold
|
||||
+# sci(ret)
|
||||
+# return ret
|
||||
+
|
||||
+# # Autogenerated by boilerplate.py. Do not edit as changes will be lost.
|
||||
+# @_autogen_docstring(Axes.triplot)
|
||||
+# def triplot(*args, **kwargs):
|
||||
+# ax = gca()
|
||||
+# # Deprecated: allow callers to override the hold state
|
||||
+# # by passing hold=True|False
|
||||
+# washold = ax._hold
|
||||
+# hold = kwargs.pop('hold', None)
|
||||
+# if hold is not None:
|
||||
+# ax._hold = hold
|
||||
+# from matplotlib.cbook import mplDeprecation
|
||||
+# warnings.warn("The 'hold' keyword argument is deprecated since 2.0.",
|
||||
+# mplDeprecation)
|
||||
+# try:
|
||||
+# ret = ax.triplot(*args, **kwargs)
|
||||
+# finally:
|
||||
+# ax._hold = washold
|
||||
|
||||
-# Autogenerated by boilerplate.py. Do not edit as changes will be lost.
|
||||
-@_autogen_docstring(Axes.tripcolor)
|
||||
-def tripcolor(*args, **kwargs):
|
||||
- ax = gca()
|
||||
- # Deprecated: allow callers to override the hold state
|
||||
- # by passing hold=True|False
|
||||
- washold = ax._hold
|
||||
- hold = kwargs.pop('hold', None)
|
||||
- if hold is not None:
|
||||
- ax._hold = hold
|
||||
- from matplotlib.cbook import mplDeprecation
|
||||
- warnings.warn("The 'hold' keyword argument is deprecated since 2.0.",
|
||||
- mplDeprecation)
|
||||
- try:
|
||||
- ret = ax.tripcolor(*args, **kwargs)
|
||||
- finally:
|
||||
- ax._hold = washold
|
||||
- sci(ret)
|
||||
- return ret
|
||||
-
|
||||
-# Autogenerated by boilerplate.py. Do not edit as changes will be lost.
|
||||
-@_autogen_docstring(Axes.triplot)
|
||||
-def triplot(*args, **kwargs):
|
||||
- ax = gca()
|
||||
- # Deprecated: allow callers to override the hold state
|
||||
- # by passing hold=True|False
|
||||
- washold = ax._hold
|
||||
- hold = kwargs.pop('hold', None)
|
||||
- if hold is not None:
|
||||
- ax._hold = hold
|
||||
- from matplotlib.cbook import mplDeprecation
|
||||
- warnings.warn("The 'hold' keyword argument is deprecated since 2.0.",
|
||||
- mplDeprecation)
|
||||
- try:
|
||||
- ret = ax.triplot(*args, **kwargs)
|
||||
- finally:
|
||||
- ax._hold = washold
|
||||
-
|
||||
- return ret
|
||||
+# return ret
|
||||
|
||||
# Autogenerated by boilerplate.py. Do not edit as changes will be lost.
|
||||
@_autogen_docstring(Axes.violinplot)
|
26
src/main.cpp
26
src/main.cpp
|
@ -52,6 +52,32 @@ EMSCRIPTEN_BINDINGS(python) {
|
|||
}
|
||||
|
||||
extern "C" {
|
||||
/*
|
||||
TODO: This is a workaround for a weird emscripten compiler bug. The
|
||||
matplotlib/_qhull.so extension makes function pointer calls with these
|
||||
signatures, but since nothing with that signature exists in the MAIN_MODULE,
|
||||
it can't link the SIDE_MODULE. Creating these dummy functions here seems to
|
||||
work around the problem.
|
||||
*/
|
||||
|
||||
void __foo(double) {
|
||||
|
||||
}
|
||||
|
||||
void __foo2(double, double) {
|
||||
|
||||
}
|
||||
|
||||
void __foo3(double, double, double) {
|
||||
|
||||
}
|
||||
|
||||
void __foo4(int, double, int, int, int) {
|
||||
|
||||
}
|
||||
|
||||
/* END WORKAROUND */
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
setenv("PYTHONHOME", "/", 0);
|
||||
|
||||
|
|
|
@ -149,6 +149,59 @@ ax.add_patch(dolphin_patch2)
|
|||
|
||||
plt.show()
|
||||
|
||||
%% code {"language":"py"}
|
||||
import matplotlib.pyplot as plt
|
||||
from matplotlib.tri import Triangulation
|
||||
from matplotlib.patches import Polygon
|
||||
import numpy as np
|
||||
|
||||
|
||||
def update_polygon(tri):
|
||||
if tri == -1:
|
||||
points = [0, 0, 0]
|
||||
else:
|
||||
points = triang.triangles[tri]
|
||||
xs = triang.x[points]
|
||||
ys = triang.y[points]
|
||||
polygon.set_xy(np.column_stack([xs, ys]))
|
||||
|
||||
|
||||
def motion_notify(event):
|
||||
if event.inaxes is None:
|
||||
tri = -1
|
||||
else:
|
||||
tri = trifinder(event.xdata, event.ydata)
|
||||
update_polygon(tri)
|
||||
plt.title('In triangle %i' % tri)
|
||||
event.canvas.draw()
|
||||
|
||||
|
||||
# Create a Triangulation.
|
||||
n_angles = 16
|
||||
n_radii = 5
|
||||
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()
|
||||
triang = Triangulation(x, y)
|
||||
triang.set_mask(np.hypot(x[triang.triangles].mean(axis=1),
|
||||
y[triang.triangles].mean(axis=1))
|
||||
< min_radius)
|
||||
|
||||
# Use the triangulation's default TriFinder object.
|
||||
trifinder = triang.get_trifinder()
|
||||
|
||||
# Setup plot and callbacks.
|
||||
plt.subplot(111, aspect='equal')
|
||||
plt.triplot(triang, 'bo-')
|
||||
polygon = Polygon([[0, 0], [0, 0]], facecolor='y') # dummy data for xs,ys
|
||||
update_polygon(-1)
|
||||
plt.gca().add_patch(polygon)
|
||||
plt.gcf().canvas.mpl_connect('motion_notify_event', motion_notify)
|
||||
plt.show()
|
||||
</script>
|
||||
<div id='page'></div>
|
||||
<script src='https://iodide-project.github.io/dist/iodide.pyodide-20190518.js'></script>
|
||||
|
|
Loading…
Reference in New Issue