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

Python 如何在Plotly Dash中设置数据标签,python,plotly-dash,Python,Plotly Dash,我是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'),

我是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。我只是不知道该放在哪里。任何建议都将不胜感激。谢谢

此文档页应该有帮助


您需要添加一个文本数组作为x和y的对等点,然后在其旁边设置textposition。

谢谢,@nicolaskruchten。在将上面的代码重构成更像Dash的东西之后?在第二节中,我能够非常轻松地将文本添加到情节中。再次感谢!