2017-07-28 39 views
0

我有我與matplotlib從該數據幀稱爲lineFGDF完成的線圖:PYTHON(Plotly) - 重命名軸蜱

enter image description here

我使用的代碼是:

fig, ax2 = plt.subplots(figsize=(15, 10)) 
x = lineFDF[threeYr] 
x.plot(kind='line', marker='',color='#0c1e3c') 
plt.grid(color='#e5e0e0', linestyle=':', linewidth=0.8) 

它產生這樣的:

enter image description here

這很棒,我可以在X軸上看到月份。不過,我想用Plotly來做,所以我可以讓它互動。

因此,我在Plotly中找到了一種方法,但幾個月過去了,已經被數字取代了。我如何獲取月份標籤?

這是代碼:

random_x = lineFDF[threeYr] 
trace0 = go.Scatter(
    y = random_x, 
    mode = 'lines', 
    name = 'lines' 
) 
data = [trace0] 
plotly.offline.iplot(data, filename='line-mode') 

將會產生這樣的:

enter image description here

回答

1

在TRACE0指定X。設置X等於你想看到的月份。

trace0 = go.Scatter(
    x = ['jan','feb','ma','ap','may','jun'], 
    y = [1,2,3,4,5,6], 
    mode = 'lines', 
    name = 'lines' 
) 

results in this graph。

enter image description here

+0

完美地工作。謝謝! :) – ScoutEU