这是我的代码:
import pandas as pd
import matplotlib.pyplot as plt
df = pd.DataFrame({'col_1':[1,2,3], 'col_2': [3,4,5],
'date_col': ['2014-12-15','2015-11-07','2016-01-10']})
df['date_col'] = pd.to_datetime(df['date_col']).dt.date
df.plot.area(x = 'date_col', y = ['col_1', 'col_2'])
plt.show()
答案 0 :(得分:1)
在显示之前将xticks
添加到地块中:
import pandas as pd
import matplotlib.pyplot as plt
df = pd.DataFrame({'col_1':[1,2,3], 'col_2': [3,4,5],
'date_col': ['2014-12-15','2015-11-07','2016-01-10']})
df.plot.area(x = 'date_col', y = ['col_1', 'col_2'])
plt.xticks(range(len(df.date_col)),df.date_col)
plt.show()
所需的输出:
我希望这会有所帮助。