I am using matplotlib to scatter plot a 3D matrix of points. I am using the following code:
import pylab as plt
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
my_data = np.random.rand(6500,3) # toy 3D points
fig = plt.figure()
ax = Axes3D(plt.gcf())
ax.scatter(my_data[:,0],my_data[:,1],my_data[:,2])
plt.show()
It works, so it opens a window where I can see my points.
However if I try to rotate the plot with the mouse (clicking and dragging it) it rotates REALLY slow.
I think 6500 points are not a lot for such a slow and laggy rotation, so I'm wondering if there is any pre-configuration to be done to speed it up.
Note: I tried to use Matlab and I can rotate a way bigger scatter plot without any lag, so it's not a computer limitation.
Can someone run this code and see if also experiences the slow rotation?
EDIT: Using the System monitor I can see that when rotating the points, only one CPU is used, so matplotlib is not parallelizing the process.
My computer specs:
running Ubuntu 16.10
1.2 Rotating the 3D Plot & Key Shortcuts. Click on the 3D plot window and drag the mouse on the plot. This should rotate the surface in the direction you move the mouse about the focus point (the origin, by default). To reset the viewpoint to the original one, press the Home key (fn-left arrow on Mac).
Plotly has several advantages over matplotlib. One of the main advantages is that only a few lines of codes are necessary to create aesthetically pleasing, interactive plots. The interactivity also offers a number of advantages over static matplotlib plots: Saves time when initially exploring your dataset.
%matplotlib inline sets the backend of matplotlib to the 'inline' backend: With this backend, the output of plotting commands is displayed inline within frontends like the Jupyter notebook, directly below the code cell that produced it. The resulting plots will then also be stored in the notebook document.
(revised 2021)
Matplotlib was not really designed to be interactive. Plotly (among a few others) is a plotting package that is rather feature complete and uses a webGL backend for scatter3D
that will render in your browser (and is blazing fast). More on why you might want to consider it as a go-to replacement at the bottom:
# pip install plotly
import numpy as np
import plotly.graph_objects as go
my_data = np.random.rand(6500,3) # toy 3D points
marker_data = go.Scatter3d(
x=my_data[:,0],
y=my_data[:,1],
z=my_data[:,2],
marker=go.scatter3d.Marker(size=3),
opacity=0.8,
mode='markers'
)
fig=go.Figure(data=marker_data)
fig.show()
I use plotly as a replacement for matplotlib because:
json
ish)If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With