有点背景信息:我对编程非常新手,这是我的第一个脚本的一小部分。这个特定部分的目标是显示一个Seaborn热力图,其中y轴表示垂直深度,x轴表示时间,热函数表示科学测量的强度。
如果这个问题在其他地方已经得到了回答,我想道歉,因为我的搜索能力可能失败了。
sns.set()
nametag = 'Well_4_all_depths_capf'
Dp = D[D.well == 'well4']
print(Dp.date)
heat = Dp.pivot("depth", "date", "capf")
### depth, date and capf are all columns of a pandas dataframe
plt.title(nametag)
sns.heatmap(heat, linewidths=.25)
plt.savefig('%s%s.png' % (pathheatcapf, nametag), dpi = 600)
这是从“print(Dp.date)”打印出来的内容,所以我相当确定数据框的格式符合我想要的格式,特别是年、日、月。
0 2016-08-09
1 2016-08-09
2 2016-08-09
3 2016-08-09
4 2016-08-09
5 2016-08-09
6 2016-08-09
...
但是,当我运行它时,日期轴总是打印出空时间(00:00等),而我不想要这些时间。
有没有办法从日期轴中删除这些时间?
问题是在上面一个单元格中我使用了此函数来扫描文件名并创建具有日期的列吗?使用datetime而不是仅使用日期函数是错误的吗?
D['date']=pd.to_datetime(['%s-%s-%s' %(f[0:4],f[4:6],f[6:8]) for f in
D['filename']])
ValueError: The number of FixedLocator locations (13), usually from a call to set_ticks, does not match the number of ticklabels (25).
,所以不确定是否正确... - Chris Withers