2

在此处输入图像描述

我有一个这样的图表,它记录了 21 天的每小时数据,标签如下:01-30 00:00, 01-30 01:00 ....现在它们不可读,所以我只想设置一个每天的标签,所以只显示每天的第一个标签:01-30 00:00、01-31 00:00 等

我的代码是:

fig1 = plt.figure()  
ax = fig1.add_subplot(111)
ind = np.arange(len(timelist))
ax.bar(ind,reqlist,color='b')
ax.set_xlim((0,len(timelist)))
ax.set_ylabel('Number of request/video',size='x-large')
ax.set_title('Request per hour North',size='xx-large')
ax.set_xticks(ind)
ax.set_xticklabels(timelist,rotation=17)

timelist 是一个字符串列表:["01-30 00:00", "01-30 00:01".....]

4

1 回答 1

1

您可以尝试仅提供您想要的标签,并为其余的提供一个空字符串。
例如,如果您每 24 天(一天)只需要一个标签:

newlist = []
for index, item in enumerate(timelist):
    if index % 24 == 0:
        newlist.append(item)
    else:
        newlist.append('')
ax.set_xticklabels(newlist, rotation=17)
于 2012-08-20T16:43:20.910 回答