我是新来的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
。我只是不知道该放在哪里。任何建议都将不胜感激。谢谢
这个文档页面https://plotly.com/python/text-and-annotations/应该有帮助
您需要添加一个
text
数组作为x
和y
的对等方,然后在它旁边设置textposition
相关问题 更多 >
编程相关推荐