如何使用 Plotly-Dash 设置滑块和选择器的范围

2022-01-21 00:00:00 python plotly plotly-dash

问题描述

我正在尝试使用 Dash 重新创建此 Plotly 示例,但我无法获得按钮和范围滑块.有谁知道我该怎么做?

I am trying to recreate this Plotly example with Dash, but I cannot get the buttons and the range slider. Does anyone know how I can do this?

这就是我尝试过的:

traces =[{
            'x':df.index,
            'y':df.level,
            'type': 'scatter',
            'mode': 'lines',
            'name': 'a_level'
    }]
    graphs.append(dcc.Graph(
        id='a_level',
        figure={
            'data': traces,
            'layout': {
                    'type': 'date',
                    'rangeslider': {'visible':True},
                    'margin': {'b': 0, 'r': 10, 'l': 60, 't': 0}
            }
        }
    )


解决方案

rangesliderxaxis 的一个属性.

我使用这样的东西:

app = dash.Dash(__name__, external_stylesheets=['https://codepen.io/chriddyp/pen/bWLwgP.css'])
    app.layout = html.Div([
        dcc.Graph(
            id='bar_plot',
            figure=go.Figure(
                data=area,
                layout=go.Layout(
                    xaxis={
                        'rangeslider': {'visible':True},
                        'rangeselector': {'visible':True, 'buttons':[{'step':'all'}, {'step':'day'}, {'step':'hour'}]}
                    },
                )))
    ])

相关文章