【发布时间】:2019-08-21 07:39:05
【问题描述】:
我正在尝试使用以下代码将 x-ticks 设置为 [Jan., Feb., ...]
import matplotlib.pyplot as plt
from matplotlib.dates import MonthLocator, DateFormatter
fig = plt.figure(figsize=[10, 5])
ax = fig.add_subplot(111)
ax.plot(np.arange(1000))
ax.xaxis.set_major_locator(MonthLocator())
ax.xaxis.set_major_formatter(DateFormatter('%b'))
我想知道为什么所有的 x-ticks 都消失了?我参考this implementation写了上面的代码
非常感谢。
【问题讨论】:
-
假设您不想显示 0001 年的数据。因此您需要指定 x 值作为您的日期。
-
嗨,很抱歉我不能完全关注你。你能说得更具体点吗?
-
plt.plot(x, y)--x应该在这里?在上面的代码中,您只提供y。 -
x默认是y的索引
-
是的。但是一个月有多少个指数呢?
标签: python matplotlib