Replacing a Tag Label (Dash)

I can not get the following to build a label label

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')
        ])

So, basically I have a numerical representation of the chart, however, when I change the tick and label values, these numerical labels disappear, however I do not see the dates that I expected to be there. Am I missing a switch to display these labels?

+4
source share
1 answer

tickvalsshould be the actual x-axis values ​​where your ticks should be located, not the labels. Not knowing what your actual data looks like, here is an example with some compiled data:

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 0, 2017-02-01 1 2017-03-01 2 x. 2017-02-01 (, , 1 self.tickvals) , , 1.5, . , .

+2

Source: https://habr.com/ru/post/1680872/


All Articles