Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jupyter | How to rotate 3D graph [duplicate]

I am not sure about how to rotate graph in Python Jupyter notebook, its static for me and not rotate on mouse movement

from mpl_toolkits.mplot3d import Axes3D import matplotlib.pyplot as plt  fig = plt.figure() ax = fig.add_subplot(111, projection='3d')  x =[1,2,3,4,5,6,7,8,9,10] y =[5,6,2,3,13,4,1,2,4,8] z =[2,3,3,3,5,7,9,11,9,10]  ax.scatter(x, y, z, c='r', marker='o')  ax.set_xlabel('X Label') ax.set_ylabel('Y Label') ax.set_zlabel('Z Label')  plt.show() 

enter image description here

like image 899
Vineet Avatar asked Nov 15 '17 15:11

Vineet


People also ask

How do you rotate a 3D plot?

Use the Rotate3D tool on the toolbar to enable and disable rotate3D mode on a plot, or select Rotate 3D from the figure's Tools menu.

How do you plot a 3D graph in Jupyter notebook?

To generate an interactive 3D plot first import the necessary packages and create a random dataset. Now using Axes3D(figure) function from the mplot3d library we can generate a required plot directly. Pass the data to the 3D plot and configure the title and labels.

How do you plot a 3D scatter plot in Python?

Generally 3D scatter plot is created by using ax. scatter3D() the function of the matplotlib library which accepts a data sets of X, Y and Z to create the plot while the rest of the attributes of the function are the same as that of two dimensional scatter plot.


1 Answers

To enable interactivity you need to use the notebook backend of matplotlib. You can do this by running %matplotlib notebook.

This must be done before you plot anything, e.g.:

%matplotlib notebook  import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import axes3d      fig = ... 
like image 174
Hannes Ovrén Avatar answered Sep 27 '22 20:09

Hannes Ovrén