嗨我在圖中繪製了兩條線,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