【问题标题】:creating scatterplot matrix using Plotly Dash in Python在 Python 中使用 Plotly Dash 创建散点图矩阵
【发布时间】:2020-05-25 20:37:57
【问题描述】:

我已经搜索了几个小时,但找不到任何在 python 中使用 Plotly Dash 框架的散点图矩阵示例。 (使用 Dash 而不是 Plotly create_scatterplotmatrix)

谁能给我一个使用 Dash 框架的散点图矩阵的简单示例?

【问题讨论】:

  • 散点图示例在那里website
  • 您介意提供mcve吗?这将是一个很好的 df 样本和您正在寻找的输出的想法。
  • @PirateX 我正在寻找散点图矩阵而不是散点图。当然还有样本,而不是可视化

标签: python plot plotly scatter-plot plotly-dash


【解决方案1】:

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 的示例。

【讨论】:

    猜你喜欢
    • 2021-11-04
    • 2019-06-27
    • 1970-01-01
    • 2011-04-13
    • 2018-11-11
    • 2014-11-09
    • 2016-10-07
    • 2021-10-28
    • 2019-12-02
    相关资源
    最近更新 更多