Python 熊猫时间间隔范围绘图,以绘制登记长度,以及相对间距和顺序
我预计最长7-8年的时间范围(在注册研究中收集的总时间数据) 创建时间间隔的快速可视化将最大时间间隔膨胀到100年以上 我在下面发布了我的代码和输出:有没有人看到我如何处理日期的问题。Python 熊猫时间间隔范围绘图,以绘制登记长度,以及相对间距和顺序,python,matplotlib,pandas,Python,Matplotlib,Pandas,我预计最长7-8年的时间范围(在注册研究中收集的总时间数据) 创建时间间隔的快速可视化将最大时间间隔膨胀到100年以上 我在下面发布了我的代码和输出:有没有人看到我如何处理日期的问题。 基本上,我取总范围和主题间隔,并将其转换为天 def timeplot(dt): # -- get time length dt = dt.reset_index() pd.to_datetime( dt['realtime'] ) #print dt.dtypes #print(
基本上,我取总范围和主题间隔,并将其转换为天
def timeplot(dt):
# -- get time length
dt = dt.reset_index()
pd.to_datetime( dt['realtime'] )
#print dt.dtypes #print( dt.head(1) )
grpt = dt.groupby('subject_id')['realtime']
# -- timestamps min, max
subj_min = grpt.min() ; subj_max = grpt.max() ;descr = grpt.describe()
# -- time range to ints
# no. of days between (int)
mn = subj_max - subj_min
intdy = mn.map(lambda x: int(x.days))
#intsj = subj_min.map(lambda x: int(x.days))
#print('#deltaT', mn)
#print('days ', mn.map(type) )
print('day as int**: ', intdy )
# -- y is number of subjects,
y = xrange( dt.subject_id.nunique() )
# -- x is days int
mmin = dt.realtime.min()
mmax = dt.realtime.max()
mlen = mmax - mmin;
totdys = int(mlen.days)
# [mmin .. (min .. x1/2 .. max) .. mmax]
subrange = subj_min - mmin
subrdays = subrange.map(lambda x: int(x.days) )
#print('##! ', len(subrdays), subrdays[:10])
x5 = subrdays + intdy/2
print( '## ', totdys, len(y), len(x5) )
# plot
fig, ax = plt.subplots()
ax.errorbar( x5, y, xerr=(intdy*10), fmt='ok', ecolor='grey',elinewidth=50, alpha=0.9)
ax.set_xlabel("days");ax.set_ylabel("subjects")
由于某些原因,错误条也是垂直的(我猜这只是一个缩放问题。)
我试图让我的情节看起来更像它下面的情节
**呃,精确性并不重要,只是简单地寻找视觉启发的相对顺序、间距和长度。作为一个快速破解,x轴可以被覆盖(标记为年)吗?我尝试缩放横杆使它垂直
如果您提供一个包含示例数据的工作示例,这会有所帮助。