2017-07-28 99 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