How to Set Data Labels in Plotly Dash

I'm new to Dash (just started today) and am trying to add some data labels to a toy data set.

My code is as follows:

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)

From reading through the docs, I see that I need to set textposition. I just don't know WHERE to set it. Any advice would be much appreciated. Thanks!

1 Answer

This documentation page should help out!

You'll need to add a text array as a peer of x and y and then alongside it set textposition as well.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Alexander Ross

Alexander Ross

Gaming, Esports & Interactive Media Writer

Alexander Ross has covered the video game industry for a decade, writing deep dives on game design, esports tournaments, VR developments, and gaming culture.

Share this article
Twitter Facebook Pinterest