Matplotlib does not display interactive graph in Ipython

2.5k Views Asked by At

I am trying to plot a 3D scatter plot with matplotlib from IPython. I am able to make a plot when I use the inline magic command as follows

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
%matplotlib inline

y = np.arange(10)
x = np.arange(10)
z = np.arange(10)

plt.figure()
ax = plt.axes(projection='3d')
ax.scatter(x,y,z)

But because the plot is inline, it is not interactive and I can not rotate it to the viewing angle I want. When I replace the inline command with

%matplotlib

I get

<mpl_toolkits.mplot3d.art3d.Path3DCollection at 0x7fb80bf40358>

as output, but no window or graph appears. If I add

plt.show()

to the end of the script, nothing happens. How do I plot an interactive graph in IPython?

1

There are 1 best solutions below

0
On

You may want to use pylab to get rid of most imports and all the namespaces:

%pylab
from mpl_toolkits.mplot3d import Axes3D

y = rand(100)
x = rand(100)
z = rand(100)

ax = subplot(projection='3d')
ax.scatter(x, y, z)

See https://plot.ly/ for interactive inline plots.