I am attempting to create a Seaborn heatmap to visualize scientific measurements. The heatmap should display vertical depth on the y-axis, time on the x-axis, and the intensity of the measurement as the heat function. The data is structured with 'depth', 'date', and 'capf' as columns in a pandas DataFrame.
Here is the code snippet I'm working with:
sns.set()
nametag = 'Well_4_all_depths_capf'
Dp = D[D.well == 'well4']
print(Dp.date)
heat = Dp.pivot("depth", "date", "capf")
plt.title(nametag)
sns.heatmap(heat, linewidths=.25)
plt.savefig('%s%s.png' % (pathheatcapf, nametag), dpi=600)
The output from print(Dp.date)
shows that the dates are formatted as I desire (year-day-month), but when I run the heatmap, the date axis incorrectly displays times (00:00 etc.), which I want to remove.
Here's the current output of Dp.date
:
0 2016-08-09
1 2016-08-09
...
6 2016-08-09
Is the problem related to how I'm handling dates? Specifically, could the use of pd.to_datetime
when creating the 'date' column be an issue? Here's how I've parsed dates from filenames:
D['date'] = pd.to_datetime(['%s-%s-%s' % (f[0:4], f[4:6], f[6:8]) for f in D['filename']])
I suspect this formatting might be causing the issue with unwanted time data appearing on the x-axis of the heatmap. How can I remove these timestamps?
ValueError: The number of FixedLocator locations (13), usually from a call to set_ticks, does not match the number of ticklabels (25).
, so not sure it's quite right... – Misadventure