如何使 x 标签更具可读性?

How to make the x-labels more readable?

所以我有一个时间序列图,但问题是x标签是一个在另一个之上,我想知道如何更正它?

代码如下:

def time_series(start, end):
    time_series_df = Res[['Timestamp', 'Ammonia']][(Res['Timestamp'] >= start) & (Res['Timestamp'] <= end)]
    x = time_series_df.Timestamp
    y = time_series_df.Ammonia
    plt.plot(x,y)
    plt.xlabel('Time')
    plt.ylabel('Ammonia Value')
    plt.title('Ammonia Time Series')
    return plt.show()

当我显示它时:

time_series('2013-11-01 00:00:00','2013-12-31 23:00:00')

这是我得到的:

正如我在对您的 post 的评论中所建议的,您可以通过以下方式旋转标签:

import matplotlib.pyplot as plt
import random

x = random.sample(range(1, 10000), 100)
y = random.sample(range(1, 10000), 100)
plt.plot(x, y, 'ro')
plt.xticks(rotation = 40) # 40 is the rotation angle
plt.show()

如 matplotlib 中所述references