Reputation: 11657
I have written the following test code to demonstrate the problem:
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import pyplot as plt
x=np.linspace(0,1,10)
y=np.linspace(0,1,10)
X,Y=np.meshgrid(x,y)
ax = plt.gca(projection='3d')
ax.plot_surface(X,Y,X+Y)
plt.show()
This code plots a 3d surface but I cannot grab and rotate it. Where is the problem?
Upvotes: 4
Views: 6136
Reputation: 809
When I have had this same problem, adding the following lines before importing anything matplotlib related (i.e. above line 2 in your example) fixes the issue.
import matplotlib
matplotlib.use('Qt4Agg')
So, your example would be:
import numpy as np
import matplotlib
matplotlib.use('Qt4Agg')
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import pyplot as plt
x=np.linspace(0,1,10)
y=np.linspace(0,1,10)
X,Y=np.meshgrid(x,y)
ax = plt.gca(projection='3d')
ax.plot_surface(X,Y,X+Y)
plt.show()
Upvotes: 3