2017-09-26 94 views
1

我正在嘗試使用seaborn將以下數據集繪製爲barplot暨pointplot。Seaborn plot爲x軸時間戳標籤添加了額外的零

enter image description here

但是時間戳在x軸標籤示出了在端部附加零如下所示

enter image description here

我使用的代碼是

import matplotlib.pyplot as plt 
import seaborn as sns 
fig, ax1 = plt.subplots() 
# Plot the barplot 
sns.barplot(x='Date', y=y_value, hue='Sentiment', data=mergedData1, ax=ax1) 
# Assign y axis label for bar plot 
ax1.set_ylabel('No of Feeds') 
# Position the legen on the right side outside the box 
plt.legend(loc=2, bbox_to_anchor=(1.1, 1), ncol=1) 
# Create a dual axis 
ax2 = ax1.twinx() 
# Plot the ponitplot 
sns.pointplot(x='Date', y='meanTRP', data=mergedData1, ax=ax2, color='r') 
# Assign y axis label for point plot 
ax2.set_ylabel('TRP') 
# Hide the grid for secondary axis 
ax2.grid(False) 
# Give a chart title 
plt.title(source+' Social Media Feeds & TRP for the show '+show) 
# Automatically align the x axis labels 
fig.autofmt_xdate() 
fig.tight_layout() 

不知道發生了什麼問題。請幫我解決一下這個。謝謝

+0

沒有什麼是錯誤的,您的日期數據包括數據,並且時間下降到很多分秒。你可以把它改爲只適用於你的數據的日期'DF ['Date'] = DF ['Date']。dt.date' –

回答

1

最簡單的解決方案是將文本拆分爲字母「T」,因爲其餘部分可能不需要。

ax.set_xticklabels([t.get_text().split("T")[0] for t in ax.get_xticklabels()]) 
+0

謝謝。我使用'split(「。」)[0]'來分隔毫秒部分。 – Sreenath1986