I'm writing an interface for making 3D scatter plots in matplotlib, and I'd like to access the data from a python script. For a 2D scatter plot, I know the process would be:
import numpy as np
from matplotlib import pyplot as pltfig = plt.figure()
ax = fig.add_subplot(111)
h = ax.scatter(x,y,c=c,s=15,vmin=0,vmax=1,cmap='hot')
data = h.get_offsets()
With the above code, I know that data would be a (N,2)
numpy array populated with my (x,y)
data. When I try to perform the same operation for 3D data:
import numpy as np
from matplotlib import pyplot as plt
from mpl_toolkits.mplot3d import Axes3Dfig = plt.figure()
ax = Axes3D(fig)
h = ax.scatter(x,y,z,c=c,s=15,cmap='hot',vmin=0,vmax=1)
data = h.get_offsets()
The resulting data
variable is still an (N,2)
numpy array rather than a (N,3)
numpy array. The contents of data
no longer match any of my input data; I assume that data
is populated with the 2D projections of my 3D data, but I would really like to access the 3D data used to generate the scatter plot. Is this possible?