forked from plotly/dash-recipes
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdash-annotations.py
37 lines (30 loc) · 898 Bytes
/
dash-annotations.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import dash
import dash_core_components as dcc
import dash_html_components as html
app = dash.Dash()
GDP = {'name': 'GDP_yoy',
'x': [2012, 2013, 2014, 2015, 2016],
'y': [103.5, 101.3, 100.7, 97.2, 99.8]}
def make_annotation_item(x, y):
return dict(xref='x', yref='y',
x=x, y=y,
font=dict(color='black'),
xanchor='left',
yanchor='middle',
text='Annotation: {} '.format(y),
showarrow=False)
ANNOTATIONS = [make_annotation_item(x=GDP['x'][-1], y=GDP['y'][-1])]
app.layout = html.Div(children=[
dcc.Graph(
id='example-graph',
figure={
'data': [GDP],
'layout': {
'xaxis': dict(range=[2010, 2020]),
'annotations': ANNOTATIONS
}
}
)
])
if __name__ == '__main__':
app.run_server(debug=True)