繁体   English   中英

3D scatter plot with in Python 从日期中提取

[英]3D scatter plot with in Python extracted from Dates

问题:

有没有办法可以将天转换为字符串而不是十进制值? 对于月份也是如此。

注意:我已经访问过这个3D Scatterplot with strings in Python )答案,它不能解决我的问题。

我正在做一个自我项目,我试图从我从谷歌活动中检索到的数据中为我的通勤创建 3D 图表。 作为参考,我正在关注本指南: https://nvbn.github.io/2018/05/01/commute/

我能够根据月 + 时间日 + 时间属性创建信息丰富的 2D 图表,但是我希望将这 2 个图表结合起来。

我要创建的 3D 图表需要 3 个属性Day (Mon/Tue), Month (Jan/Feb), Time taken

鉴于 matplotlib 立即不支持图表中的字符串值,我已将数字用于日 (0-7) 和月 (1-12)。 但是,对于几天的十进制值,图表似乎有点模糊。 看起来像以下在此处输入图像描述

我当前的代码看起来像这样,检索weekday()以获取天数,并month获取。

# How commute is calculated and grouped
import pandas as pd
#{...}
def get_commute_to_work():
#{...}
 yield Commute_to_work(pd.to_datetime(start.datetime), start.datetime, end.datetime, end.datetime - start.datetime)

#Now creating graph here

fig, ax = pyplot.subplots(subplot_kw={'projection': '3d'})
ax.grid()
ax.scatter([commute.day.weekday() for commute in normalised],
           [commute.day.month for commute in normalised],
           [commute.took.total_seconds() / 60 for commute in normalised])

ax.set(xlabel='Day',ylabel='Month' ,zlabel='commute (minutes)',
       title='Daily commute')
ax.legend()
pyplot.show()

注意。 如果您想查看此代码的详细信息,请在此处的github上找到

你可以试试这个(虽然我还没有验证 3d plot):

x_tick_labels = ['Sun','Mon','Tue','Wed','Thurs', 'Fri', 'Sat']

# Set number of ticks for x-axis
x = np.linspace(1.0, 4.0, 7)  # Why you have 9 days in a week is beyond me
ax.set_xticks(x)
# Set ticks labels for x-axis
ax.set_xticklabels(x_ticks_labels, rotation='vertical', fontsize=18)

您可以重复类似的程序数月。

这个答案的来源是here

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM