我无法得到以下内容来绘制ticklabels
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')
])
所以基本上我有一个条形图的数字表示,但是当我更改刻度值和刻度标签时,那些数字标签消失了,但是我没有看到我期望在那里的日期。我错过了显示这些标签的开关吗?
答案 0 :(得分:4)
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
映射到x轴上的相应值0
,2017-02-01
到1
和2017-03-01
到2
。我可能遗漏了2017-02-01
(以及1
中的self.tickvals
,以防万一会产生太多标签或选择任意值,例如1.5
来绘制我的标签。在我们讨论条形图时,后一个例子缺乏有用的应用程序。