繁体   English   中英

Plotly(Dash)刻度标签覆盖

[英]Plotly (Dash) tick label overwriting

我无法得到以下内容来绘制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')
        ])

所以基本上我有一个条形图的数字表示,但是当我更改刻度值和刻度标签时,那些数字标签消失了,但是我没有看到我期望在那里的日期。 我错过了显示这些标签的开关吗?

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 (因此在self.tickvals中为1 )。 在我们讨论条形图时,后一个例子缺乏有用的应用程序。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM