I am trying to learn how to create a 3D cube plot to visualize data. Here I am creating some mock data to represent sales of items. On the x axis, I am trying to plot the year, Y axis I am trying to plot the items sold, and the Z axis would have the prices these items sold at. This would be an example of one row of the mock dataset:
year category sales
2002 clothes 275
again, having year on the x-axis, category on the y-axis, and sales on the z-axis.
What I currently have is:
def plot_cube():
x = []
y = []
z = []
#creating data to plot. 300 total samples. x list will contain years (2001, 2002, and 2003
for i in range(100):
x.append(2001)
for i in range(100):
x.append(2002)
for i in range(100):
x.append(2003)
# creating data to plot. 300 total samples. y list will contain items being sold (clothes, shoes, and hats)
for i in range(100):
y.append("clothes")
for i in range(100):
y.append("shoes")
for i in range(100):
y.append("hats")
# creating data to plot. 300 samples. z list will contain how much in sales
for i in range(300):
z.append(random.randint(200, 300))
arr = []
for i in range(300):
arr.append([x[i], y[i], z[i], 0])
data = zip(*arr)
fig = pyplot.figure()
ax = fig.add_subplot(111, projection='3d')
ax.scatter(data[0], data[1], data[2], c=data[3])
pyplot.show()
#returning x,y,z as lists
return x, y, z
I grabbed methods from different forums to put this together, as I saw a lot of people using the zip() function. However, this is currently not working for me, as it returns the error:
TypeError: 'zip' object is not subscriptable
I saw some people fix this by changing 'data = zip(*arr)' to 'data = list(zip(*arr))', but when I do this, I then get a different error: ValueError: could not convert string to float: 'clothes'
Any ideas?