2017-07-06 95 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)。当我们谈论条形图时,后面的例子缺乏有用的应用程序。