如何在Plotly Dash中设置数据标签

2024-05-23 20:00:12 发布

您现在位置:Python中文网/ 问答频道 /正文

我是新来的Dash(今天刚开始),我正在尝试向玩具数据集添加一些数据标签

我的代码如下:

import dash
import dash_html_components as html
import dash_core_components as dcc

#start the application

app = dash.Dash()

app.layout = html.Div(children=[html.H1(children='Modes of Transportation'),
                                html.Div(children = 'Explanatory text would be inserted here...'),
                                dcc.Graph(id='dash_graph',
                                    figure = {'data': [{'x':['red', 'white', 'blue'], 'y':[10, 20, 30], 'type': 'bar', 'name':'Cars'},
                                    {'x':['red', 'white', 'blue'], 'y':[5, 10, 15], 'type': 'bar', 'name':'Boats'},
                                    {'x':['red', 'white', 'blue'], 'y':[2, 4, 6], 'type': 'bar', 'name':'Trains'},                              
                                    ],

                                    'layout':{'title':'Modes of Transportation', 
                                              'xaxis':{'title':'Mode', 'type':'category'},
                                              'yaxis':{'title':'Trips per Hour'}
                                              }
                                              }),

                                dcc.Graph(id='dash_graph two',
                                    figure = {'data': [{'x':['orange', 'purple', 'blue'], 'y':[1, 2, 3], 'type': 'bar', 'name':'Mode'},],
                                    'layout':{'title':'Modes of Transportation', 'xaxis':{'title':'Mode', 'type':'category'}, 'yaxis':{'title':'Per Hour'}}})


])


if __name__ == '__main__':
    app.run_server(debug = True)

通过阅读文档,我发现我需要设置textposition。我只是不知道该放在哪里。任何建议都将不胜感激。谢谢


Tags: ofnameimportapptitlehtmltypebar