如何获得该系列图的标记x值?

问题描述 投票:2回答:2

我在用创建的系列x中的索引值标记图的x刻度时遇到麻烦。下面是代码

import matplotlib.pyplot as plt
import pandas as pd

x = pd.Series([421, 122, 275, 847, 175])
index_values = ['2014-01-01', '2014-01-02', '2014-01-03', '2014-01-04',
               '2014-01-05']
x.index = index_values
x.plot()
plt.show()

这是返回的图形(x轴上没有刻度):“

所以我的问题是:如何用index_values中的日期标记x刻度(它们也是x系列中的索引)?

python matplotlib graph series
2个回答
0
投票

您可以使用提供的方法在轴上放置标签,如下所示:

plt.ylabel('my Y label')
plt.xlabel('my X label')
plt.show()

0
投票

您可以直接通过以下方法设置xticks:

plt.xticks(x.index, index_values) 
© www.soinside.com 2019 - 2024. All rights reserved.