嗨我在图中绘制了两条线,x轴是从'2016-04-01'到'2017的日期时间-03-31',网格线宽度显示的值为一个月,即30天,但我想要的网格线宽度为50天。我的意思是我想显示x轴的日期值是:2016-04-01,2016-05-21,2016-07-10,2016-10-18,2016-12-07,2017-01- 26,2017-03-17。python2.7:如何绘制图中x轴网格线的值
牛逼
我的代码如下:
import seaborn as sn
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
sn.set_style("darkgrid")
xfmt = mdates.DateFormatter('%Y-%m-%d')
fig = plt.figure(figsize=(15,4))
ax = fig.add_subplot(111)
ax.xaxis.set_major_formatter(xfmt)
lst_predictions = list(predictions2)
len_predictions = len(lst_predictions)
plt.plot(lst_index, list(test_y2), label = 'actual')
plt.ylim(ymin=0)
plt.ylim(ymax=140)
plt.xlim([lst_index[0], lst_index[-1]])
plt.plot(lst_index, lst_predictions, label='pred')
plt.legend(loc="upper left")
plt.grid(True)
这是相当难以得到电网的50天间距和让电网的四月一号开始。既是要求? – ImportanceOfBeingErnest
Apri 1st是lst_index的第一个日期,只是第一个索引是好的。是的,我想获得50天的网格间隔。 – tktktk0711
我在下面提供了一个答案,即使我不知道如何同时满足这两个要求。您可以选择是否标记第一个索引,并使用每月报价或间隔50天对您更重要。 – ImportanceOfBeingErnest