想請教關於matplotlib的X軸問題
資料來源是pymysql取出再用pandas作載入
pandas的資料如下
day scl sft fcl fft RI
0 2019-11-05 11644.03 132 11645 57204 -28.76
1 2019-11-06 11653.07 68 11653 55694 -27.84
2 2019-11-07 11606.56 50 11596 53227 -21.91
3 2019-11-08 11579.54 15 11573 52106 -17.73
4 2019-11-11 11427.28 32 11437 52263 -8.11
5 2019-11-12 11520.37 47 11523 50161 -14.99
6 2019-11-13 11467.83 -63 11466 49928 -9.23
7 2019-11-14 11450.42 43 11456 48476 -7.69
8 2019-11-15 11525.60 43 11532 45324 -8.76
9 2019-11-18 11599.78 31 11593 45798 -10.09
10 2019-11-19 11656.40 110 11644 44634 -6.97
11 2019-11-20 11631.20 10 11607 40968 -19.56
12 2019-11-21 11558.27 -98 11544 42761 -20.27
13 2019-11-22 11566.80 -1 11556 41154 -11.22
14 2019-11-25 11561.58 15 11565 41432 -9.39
15 2019-11-26 11576.82 4 11618 45694 -17.31
16 2019-11-27 11647.46 26 11647 47197 -26.36
17 2019-11-28 11617.08 15 11614 41713 -5.73
18 2019-11-29 11489.57 -126 11465 35843 14.43
19 2019-12-02 11502.83 35 11502 41888 -8.90
<class 'pandas.core.frame.DataFrame'>
若以下列程式碼
fig = plt.figure(figsize=(75,20)) #指定繪圖區尺寸
ax = fig.add_subplot(1,1,1)
(X點)
ax.set_xticks(range(0,len(df['day']),5)) #設定X軸的刻度為每十天顯示一次
ax.set_xticklabels(df['day'][::5],rotation=45) #顯示X軸並將顯示轉45度
(Y點)
plt.show()
呈現圖
https://imgur.com/qSLBER3
將【ax.plot(df['day'],df['fcl'],label="期貨收盤",color="blue",linewidth=2)】放在X點;X軸全部擠在左邊,資料擠在右邊
呈現圖
https://imgur.com/kP2BRbP
若將【ax.plot(df['day'],df['fcl'],label="期貨收盤",color="blue",linewidth=2)】放在Y點;資料會顯示,但X軸無資料
呈現圖
https://imgur.com/aLloCcU
小弟只是靠網路上的資料自學與拼湊;再麻煩各位先進指出小弟的盲點
感謝