Reputation: 327
When creating a heatmap via seaborn seaborn==0.7.0.dev0
my axis starts two hours later.
The DataFrame used to create the heatmap starts at:
2015-05-19 21:10:00
The first get_xticklabels of the heatmap created via seaborn however is 2015-05-19 23:10:00
.
The heatmap is created via
sns.heatmap(df_test.T, xticklabels=True, yticklabels=True, ax=ax)
What am I missing here? This example (using seaborn 0.7 and 0.6) will start one hour later, in my real data it is even 2 hours.
import seaborn as sns
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
index = pd.date_range('1/1/2000', periods=60*60*12, freq='s')
df = pd.DataFrame({'a': pd.Series(np.random.randn(len(index)), index=index),
'b': pd.Series(np.random.randn(len(index)), index=index)})
#create boolean vars
df.a = df.a > 0
df.b = df.b > 0
df = df.resample('1Min', how=np.mean)
ax = plt.gca()
fig = plt.gcf()
sns.heatmap(df.T, ax=ax)
#print index
print df.index[0]
#print first xlabel
print ax.get_xticklabels()[0]
[label.set_visible(False) for label in ax.xaxis.get_ticklabels()[1:]]
plt.gcf().autofmt_xdate()
plt.show()
This will result in the following output
user@debian:/tmp$ python test.py
2000-01-01 00:00:00
Text(0.5,0,u'2000-01-01T01:00:00.000000000+0100')
Upvotes: 0
Views: 1274
Reputation: 327
Okay turns out it is the missing tz= value when creating the index which gives the offset inb the example code.
My solution (as changing tz in my DataFrame did not change this behaviour) was to set xticklabel=False
in heatmap()
and use plt.xticks()
directly.
Upvotes: 1