【发布时间】:2020-05-25 20:37:57
【问题描述】:
我已经搜索了几个小时,但找不到任何在 python 中使用 Plotly Dash 框架的散点图矩阵示例。 (使用 Dash 而不是 Plotly create_scatterplotmatrix)
谁能给我一个使用 Dash 框架的散点图矩阵的简单示例?
【问题讨论】:
标签: python plot plotly scatter-plot plotly-dash
我已经搜索了几个小时,但找不到任何在 python 中使用 Plotly Dash 框架的散点图矩阵示例。 (使用 Dash 而不是 Plotly create_scatterplotmatrix)
谁能给我一个使用 Dash 框架的散点图矩阵的简单示例?
【问题讨论】:
标签: python plot plotly scatter-plot plotly-dash
Dash 使用 Plot.ly 制作图表,因此图表的 Plot.ly 文档与 Plot.ly 的文档相同。唯一单独的文档是关于如何制作网页以及如何使用 HTML 组件和回调。您可以查看 Plotly 的散点图文档 Scatter Plots 2D Scatter Plots 3D 了解它们是如何制作的。您可以使用作为 dash 一部分的 Plotly Express 包轻松将散点图放入 Dash 应用程序中:
import dash
import dash_core_components as dcc
import dash_html_components as html
import plotly.express as px
import pandas as pd
external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
df = pd.read_csv('https://gist.githubusercontent.com/chriddyp/5d1ea79569ed194d432e56108a04d188/raw/a9f9e8076b837d541398e999dcbac2b2826a81f8/gdp-life-exp-2007.csv')
fig = px.scatter(df, x="gdp per capita", y="life expectancy",
size="population", color="continent", hover_name="country",
log_x=True, size_max=60)
app.layout = html.Div([
dcc.Graph(
id='life-exp-vs-gdp',
figure=fig
)
])
if __name__ == '__main__':
app.run_server(debug=False)
如上所示,只需调用 px.scatter(...) 并生成散点图。此示例取自 Dash 介绍文档here。要查看更高级的 Dash 散点图的输出,请参阅来自 @PirateX 的示例。
【讨论】: