1

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
  • 3
    The inline backend renders an static (png) image of the matplotlib figure. To get interactive behavior use the %matplotlib notebook backend. Commented Jun 9, 2015 at 17:52

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.