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...
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.