Matplotlib Slow 3D Scatter Rotation
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
Solution 1:
(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:
- it has great coverage (bar, scatter, line, hist, etc.)
- intuitive interactive components that are highly configurable
- portability: it can generate html plots which are easily viewed across a network(!) or saved as static file formats
- it has a clearer api than matplotlib (for full config,
json
ish) - it integrates strongly with pandas (you can use it as the backend)
- it is well supported and adoption is increasing
Post a Comment for "Matplotlib Slow 3D Scatter Rotation"