2017-07-06 31 views
4

我不能讓下面的繪製ticklabelsPlotly(DASH)刻度標籤覆蓋

self.months = [2017-01-01', 2017-02-01', ...] 



def plot_bar(self): 
     print self.data 
     app.layout = html.Div(children=[html.H1(children=''), html.Div(children='Discovered monthly'), 
     dcc.Graph(
      figure=go.Figure(
      data = self.data, 
      layout=go.Layout(
       title='Streams', showlegend=True, barmode='stack', margin=go.Margin(l=200, r=0, t=40, b=20), 
       xaxis=dict(tickvals = self.months, ticktext = self.months, title='months') 
       ) 
      ), 
     style={'height': 300}, 
     id='my-graph') 
     ]) 

所以基本上我有一個條形圖的數字表示,但是當我改變刻度值和ticklabels,那些數字標籤消失,但我沒有看到我預計會在那裏的日期。我是否缺少一個開關來顯示這些標籤?

+2

你有一些樣本數據嗎? – DJK

回答

2

tickvals需要是您的刻度應放置在x軸的實際值,而不是標籤。不知道您的實際數據是什麼樣子,下面是一些虛構的數據調整後的例子:

self.months = ['2017-01-01', '2017-02-01', '2017-03-01'] 
self.data = [ 
    {'x': [0, 1, 2], 'y': [4, 1, 2], 'type': 'bar', 'name': 'SF'}, 
    {'x': [0, 1, 2], 'y': [2, 4, 5], 'type': 'bar', 'name': u'Montréal'}, 
] 

# X-Axis location for the ticks 
self.tickvals = [0, 1, 2] 

def plot_bar(self): 
    app.layout = html.Div(children=[html.H1(children=''), html.Div(children='Discovered monthly'), 
            dcc.Graph(
             figure=go.Figure(
              data = self.data, 
              layout=go.Layout(
               title='Streams', showlegend=True, barmode='stack', margin=go.Margin(l=200, r=0, t=40, b=20), 
               xaxis=dict(tickvals = self.tickvals, ticktext = self.months, title='months') 
              ) 
             ), 
             style={'height': 300}, 
             id='my-graph') 
            ]) 

注意如何映射2017-01-01到相應的價值02017-02-0112017-03-012在x軸。如果在此產生太多標籤或選擇任意值(例如1.5)來繪製我的標籤,我可能會忽略2017-02-01(因此1self.tickvals)。當我們談論條形圖時,後面的例子缺乏有用的應用程序。