在Dash scatter图中为每个字典单独命名,可以通过在数据中添加一个"名称"字段来实现。具体步骤如下:
data = [
{"x": 1, "y": 2, "名称": "数据点1"},
{"x": 3, "y": 4, "名称": "数据点2"},
{"x": 5, "y": 6, "名称": "数据点3"}
]
import dash
import dash_core_components as dcc
import dash_html_components as html
app = dash.Dash(__name__)
app.layout = html.Div(
dcc.Graph(
id='scatter-chart',
figure={
'data': [
{'x': point['x'], 'y': point['y'], 'text': point['名称'], 'mode': 'markers'}
for point in data
],
'layout': {
'title': 'Scatter Chart',
'xaxis': {'title': 'X轴'},
'yaxis': {'title': 'Y轴'}
}
}
)
)
if __name__ == '__main__':
app.run_server(debug=True)
在上述代码中,我们通过在每个数据点的"text"字段中传递"名称"来为每个数据点命名。
这样,你就可以在Dash scatter图中为每个字典单独命名了。
领取专属 10元无门槛券
手把手带您无忧上云