python matplotlib中绘图的x轴空格日期

python matplotlib中绘图的x轴空格日期,python,matplotlib,Python,Matplotlib,我有一个python的时间序列图,它产生了我想要的结果,除了轴不太正确 下图为: 我只想在整个情节图中留出空间 我的代码如下: x2 = all_sentiment['date'] x2 = pd.Series(list(set(x2))) y2 = all_sentiment['sent_count'] fig, axes = plt.subplots(nrows=1, ncols=1, figsize=(20, 10)) axes.plot(range(len(s_pos)), s_po

我有一个python的时间序列图,它产生了我想要的结果,除了轴不太正确

下图为:

我只想在整个情节图中留出空间

我的代码如下:

x2 = all_sentiment['date']
x2 = pd.Series(list(set(x2)))
y2 = all_sentiment['sent_count']

fig, axes = plt.subplots(nrows=1, ncols=1, figsize=(20, 10))
axes.plot(range(len(s_pos)), s_pos, linewidth=2, color='green')
axes.plot(range(len(s_neg)), s_neg, linewidth=2, color='red')
#axes.set_xticks(x2.index.tolist())
axes.set_xticks(np.arange(len(x2.index.tolist())))
axes.set_xticklabels([date.strftime("%Y-%m-%d") for date in x2])
axes.margins = 0
axes.set_xlabel('Date/Time')
axes.set_ylabel('Num of Tweets')
axes.set_title('Number of Tweets Over Time - Positive and Negative')
axes.set_xlim(0, len(y2))
axes.legend(loc="upper right", labels=['Positive', 'Negative'])
fig.subplots_adjust(hspace=1)
plt.show()
你能指出我做错了什么吗


非常感谢

我首先建议删除线
轴。设置\u xlim(0,len(y2))
图子图\u调整(hspace=1)
轴。边距=0
。然后更新你的问题。我已经解决了,轴上的错误。设置_xlim(0,len(y2)),改为x2