![](/img/trans.png)
[英]Creating a scatter plot from a dataframe with dates on x-axis creates overlap
[英]Specify dates on x-axis plot from pandas dataframe
我有這個數據框:
df.payout.head()
我試圖從熊貓數據框中繪制堆積的條形圖。
我希望完整日期顯示在X軸標簽上,但是如果我僅使用grouped.index.month
或days作為grouped.index.days
天,則只能得到幾個月:
import pandas as pd
import matplotlib.pyplot as plt
df.payout = pd.to_datetime(df.payout)
grouped = df.groupby(pd.Grouper(key='payout', freq='M')).sum()
grouped.plot(x=grouped.index.month, kind='bar', stacked=True)
plt.show()
如何在X軸上獲取YYYY-MM-DD格式的payout
值?
在索引上使用所需的日期格式:
grouped.plot(x=grouped.index.strftime('%Y-%m-%d'), kind='bar', stacked=True)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.