ipython notebook 3.0.0
matplotlib 1.4.3
OS X 10.11.4
I am creating an interactive 3D scatter plot of a 3D data cube. I've included here a toy example that generates the same problems I am encountering trying to plot my data cube.
If I generate a matplot window outside of the notebook, when I manually close it (clicking the red x) it stalls with 'the wheel' until I force quit.
#Generate matplot window outside of the notebook
import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
#from matplot3d tutorial
def randrange(n, vmin, vmax):
return (vmax - vmin)*np.random.rand(n) + vmin
fig = plt.figure() ax = fig.add_subplot(111, projection='3d') n = 100 for c, m, zl, zh in [('r', 'o', -50, -25), ('b', '^', -30, -5)]:
xs = randrange(n, 23, 32)
ys = randrange(n, 0, 100)
zs = randrange(n, zl, zh)
ax.scatter(xs, ys, zs, c=c, marker=m)
ax.set_xlabel('X Label') ax.set_ylabel('Y Label') ax.set_zlabel('Z Label')
plt.show()
I've tried using mpld3 within the notebook but a non-interactive image displays along with the error
"TypeError: array([ 2., 20.]) is not JSON serializable"
#Use mpld3 within notebook
import matplotlib.pyplot as plt
import numpy as np
import mpld3
from mpl_toolkits.mplot3d import Axes3D
mpld3.enable_notebook()
def randrange(n, vmin, vmax):
return (vmax - vmin)*np.random.rand(n) + vmin
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
n = 100
for c, m, zl, zh in [('r', 'o', -50, -25), ('b', '^', -30, -5)]:
xs = randrange(n, 23, 32)
ys = randrange(n, 0, 100)
zs = randrange(n, zl, zh)
ax.scatter(xs, ys, zs, c=c, marker=m)
ax.set_xlabel('X Label')
ax.set_ylabel('Y Label')
ax.set_zlabel('Z Label')
Some quick research into JSON serialization has been non-fruitful.
What is the best way to create an interactive 3D matplotlib scatter plot that won't stall?