0

I am trying for first time to plot 3d chart and failing measurably. Getting error "Argument Z must be 2-dimensional." Not sure what should I do to make this work. I can plot sold items against both other arguments, thought it will catch this. Will appreciate any help and explanation. Dataset records sale each hour.

from mpl_toolkits.mplot3d import axes3d
from matplotlib import cm

fig = plt.figure()
ax = fig.gca(projection='3d')


X = dataset['WeekDay']
Y = dataset['Hour']
Z = dataset['SoldItems']

ax.plot_surface(X, Y, Z, rstride=8, cstride=8, alpha=0.3)
cset = ax.contourf(X, Y, Z, zdir='z', offset=0, cmap=cm.coolwarm)
cset = ax.contourf(X, Y, Z, zdir='x', offset=0, cmap=cm.coolwarm)
cset = ax.contourf(X, Y, Z, zdir='y', offset=0, cmap=cm.coolwarm)

ax.set_xlabel('X')
ax.set_xlim(0, 6)
ax.set_ylabel('Y')
ax.set_ylim(0, 23)
ax.set_zlabel('Z')
ax.set_zlim(0, 1000)

plt.show()
Andrzej
  • 1
  • 1
  • It all in one dataset. Week day is 0 to 6 (Mon-Sun), then next column is hour of the day (0 to 23), therefore each day of the week is repeated 24 times. Next column is just a number of sold items... i don't care about type of the items here. – Andrzej Apr 16 '22 at 23:41
  • See [Simplest way to plot 3D surface](https://stackoverflow.com/q/12423601/199364) and [Why Z has to be 2D](https://stackoverflow.com/a/53248136/199364). – ToolmakerSteve Apr 16 '22 at 23:58
  • Thank you. Will need to give a deeper dive into this. Still I think it is definitely possible to build 3dplot with data I have. Will need to understand how to reformat data into 2D arrays. Might be simple solution, but I need to properly understand it. was hopping for lazy copy paste solution :P – Andrzej Apr 17 '22 at 10:17

0 Answers0