Python 3D plot with dates

雨燕双飞 提交于 2020-05-29 11:24:50

问题


I am trying to make a 3D scatter plot that has the following axis: Price, Time and Dates. Essentially I want to plot the price vs the time for a single day and then do that for multiple days and stack them on an axis.

Here is the code I have so far:

 df=pd.read_csv("C:\\Desktop\\dat.csv")
 date=  df['date'].unique()
 dfd = pd.DataFrame(date)
 days= dfd.sort_values(0)

 fig= plt.figure()
 ax= fig.add_subplot(111, projection= '3d')

 xx = np.arange(len(days[0]))
 ys = [i+xx+(i*xx)**2 for i in range(len(days[0]))]
 colors = cm.rainbow(np.linspace(0, 1, len(ys)))

 for d,cc in zip(days[0],colors):

     td= df.loc[df['date'] == d]
     st= td[['time','price']]

     x = st['time']         
     y = st['price']

     x=list(x)
     y=list(y)
     ax.scatter(x,y,d,color=cc)

 plt.show()

The main problem is that x is a list with times and that d is a date. when I run the code matplotlib throws an error saying "ValueError: invalid literal for float(): 9:30:01"

The dates are in the following format : 2017.04.12, time format : 9:30:01

I am aware that I can set up tick labels for the date, but how can I handle the time?

How can I plot this 3d plot if the axis indexes contain dates and times?

来源:https://stackoverflow.com/questions/43380335/python-3d-plot-with-dates

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!