{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# 更新图\n", "\n", "无论图对象是如何构造的,都可以通过向其添加额外的轨迹并修改其属性来更新它。\n", "\n", "## 添加轨迹\n", "\n", "可以使用 {meth}`add_trace` 方法将新的轨迹添加到图对象中。这个方法接受图对象轨迹(`go.Scatter`,`go.Bar` 等的实例),并将其添加到图中。这允许您从空的图开始,并按顺序向其添加轨迹。{meth}`append_trace` 方法做同样的事情,尽管它不返回图。" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "text/html": [ " \n", " " ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.plotly.v1+json": { "config": { "plotlyServerURL": "https://plot.ly" }, "data": [ { "type": "bar", "x": [ 1, 2, 3 ], "y": [ 1, 3, 2 ] } ], "layout": { "template": { "data": { "bar": [ { "error_x": { "color": "#2a3f5f" }, "error_y": { "color": "#2a3f5f" }, "marker": { "line": { "color": "#E5ECF6", "width": 0.5 }, "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "bar" } ], "barpolar": [ { "marker": { "line": { "color": "#E5ECF6", "width": 0.5 }, "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "barpolar" } ], "carpet": [ { "aaxis": { "endlinecolor": "#2a3f5f", "gridcolor": "white", "linecolor": "white", "minorgridcolor": "white", "startlinecolor": "#2a3f5f" }, "baxis": { "endlinecolor": "#2a3f5f", "gridcolor": "white", "linecolor": "white", "minorgridcolor": "white", "startlinecolor": "#2a3f5f" }, "type": "carpet" } ], "choropleth": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "choropleth" } ], "contour": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "contour" } ], "contourcarpet": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "contourcarpet" } ], "heatmap": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "heatmap" } ], "heatmapgl": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "heatmapgl" } ], "histogram": [ { "marker": { "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "histogram" } ], "histogram2d": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "histogram2d" } ], "histogram2dcontour": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "histogram2dcontour" } ], "mesh3d": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "mesh3d" } ], "parcoords": [ { "line": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "parcoords" } ], "pie": [ { "automargin": true, "type": "pie" } ], "scatter": [ { "fillpattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 }, "type": "scatter" } ], "scatter3d": [ { "line": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatter3d" } ], "scattercarpet": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattercarpet" } ], "scattergeo": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattergeo" } ], "scattergl": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattergl" } ], "scattermapbox": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattermapbox" } ], "scatterpolar": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterpolar" } ], "scatterpolargl": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterpolargl" } ], "scatterternary": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterternary" } ], "surface": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "surface" } ], "table": [ { "cells": { "fill": { "color": "#EBF0F8" }, "line": { "color": "white" } }, "header": { "fill": { "color": "#C8D4E3" }, "line": { "color": "white" } }, "type": "table" } ] }, "layout": { "annotationdefaults": { "arrowcolor": "#2a3f5f", "arrowhead": 0, "arrowwidth": 1 }, "autotypenumbers": "strict", "coloraxis": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "colorscale": { "diverging": [ [ 0, "#8e0152" ], [ 0.1, "#c51b7d" ], [ 0.2, "#de77ae" ], [ 0.3, "#f1b6da" ], [ 0.4, "#fde0ef" ], [ 0.5, "#f7f7f7" ], [ 0.6, "#e6f5d0" ], [ 0.7, "#b8e186" ], [ 0.8, "#7fbc41" ], [ 0.9, "#4d9221" ], [ 1, "#276419" ] ], "sequential": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "sequentialminus": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ] }, "colorway": [ "#636efa", "#EF553B", "#00cc96", "#ab63fa", "#FFA15A", "#19d3f3", "#FF6692", "#B6E880", "#FF97FF", "#FECB52" ], "font": { "color": "#2a3f5f" }, "geo": { "bgcolor": "white", "lakecolor": "white", "landcolor": "#E5ECF6", "showlakes": true, "showland": true, "subunitcolor": "white" }, "hoverlabel": { "align": "left" }, "hovermode": "closest", "mapbox": { "style": "light" }, "paper_bgcolor": "white", "plot_bgcolor": "#E5ECF6", "polar": { "angularaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "bgcolor": "#E5ECF6", "radialaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" } }, "scene": { "xaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" }, "yaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" }, "zaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" } }, "shapedefaults": { "line": { "color": "#2a3f5f" } }, "ternary": { "aaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "baxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "bgcolor": "#E5ECF6", "caxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" } }, "title": { "x": 0.05 }, "xaxis": { "automargin": true, "gridcolor": "white", "linecolor": "white", "ticks": "", "title": { "standoff": 15 }, "zerolinecolor": "white", "zerolinewidth": 2 }, "yaxis": { "automargin": true, "gridcolor": "white", "linecolor": "white", "ticks": "", "title": { "standoff": 15 }, "zerolinecolor": "white", "zerolinewidth": 2 } } } } }, "text/html": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import plotly.graph_objects as go\n", "go.FigureWidget(); # 初始化\n", "\n", "fig = go.Figure()\n", "fig.add_trace(go.Bar(x=[1, 2, 3], y=[1, 3, 2]))\n", "\n", "fig.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "您还可以向图工厂或 Plotly Express 生成的图添加轨迹:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import plotly.express as px\n", "\n", "df = px.data.iris()\n", "fig = px.scatter(df, x=\"sepal_width\", y=\"sepal_length\", color=\"species\",\n", " title=\"使用 add_trace() 方法的 Plotly Express 图\")\n", "\n", "fig.add_trace(\n", " go.Scatter(\n", " x=[2, 4],\n", " y=[4, 8],\n", " mode=\"lines\",\n", " line=go.scatter.Line(color=\"gray\"),\n", " showlegend=False)\n", ")\n", "fig.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 给子图添加轨迹\n", "\n", "如果使用 `plotly.subplots.make_subplots()` 创建了图,那么可以使用 `add_trace()` 提供的 `row` 和 `col` 参数向特定的子图添加轨迹。" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from plotly.subplots import make_subplots\n", "\n", "fig = make_subplots(rows=1, cols=2)\n", "\n", "fig.add_trace(go.Scatter(y=[4, 2, 1], mode=\"lines\"), row=1, col=1)\n", "fig.add_trace(go.Bar(y=[2, 1, 3]), row=1, col=2)\n", "\n", "fig.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "这也适用于 Plotly Express 使用 `facet_row` 和/或 `facet_col` 参数创建的图。" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import plotly.express as px\n", "\n", "df = px.data.iris()\n", "\n", "fig = px.scatter(df, x=\"sepal_width\", y=\"sepal_length\", color=\"species\", facet_col=\"species\",\n", " title=\"Adding Traces To Subplots Witin A Plotly Express Figure\")\n", "\n", "reference_line = go.Scatter(x=[2, 4],\n", " y=[4, 8],\n", " mode=\"lines\",\n", " line=go.scatter.Line(color=\"gray\"),\n", " showlegend=False)\n", "\n", "fig.add_trace(reference_line, row=1, col=1)\n", "fig.add_trace(reference_line, row=1, col=2)\n", "fig.add_trace(reference_line, row=1, col=3)\n", "\n", "fig.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 添加轨迹的便利函数\n", "\n", "作为 `add_trace()` 方法的替代方法,图对象图形有一系列 `add_{trace}` 形式的方法(其中 `{trace}` 是一个轨迹类型的名称),用于构造和添加每种轨迹类型的轨迹。\n", "\n", "下面是前面的子图示例,使用 `fig.add_scatter()` 添加散点轨迹,使用 `fig.add_bar()` 添加条形轨迹。" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from plotly.subplots import make_subplots\n", "\n", "fig = make_subplots(rows=1, cols=2)\n", "\n", "fig.add_scatter(y=[4, 2, 1], mode=\"lines\", row=1, col=1)\n", "fig.add_bar(y=[2, 1, 3], row=1, col=2)\n", "\n", "fig.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 魔法下划线表示法\n", "\n", "为了更容易地使用嵌套属性,图对象构造器和许多图对象方法都支持魔法下划线表示法。\n", "\n", "这允许通过使用下划线将多个嵌套属性名连接在一起来引用嵌套属性。\n", "\n", "例如,在没有魔法下划线符号的图构造函数中指定`figure`标题需要将 `layout` 参数设置为 `dict(title=dict(text=\"A Chart\"))`。类似地,设置散点轨迹的线条颜色需要将 `marker` 属性设置为 `dict(color=\"crimson\")`。\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import plotly.graph_objects as go\n", "\n", "fig = go.Figure(\n", " data=[go.Scatter(y=[1, 3, 2], line={'color': 'crimson'})],\n", " layout={'title':\n", " {'text': 'A Graph Objects Figure Without Magic Underscore Notation'}}\n", ")\n", "\n", "fig.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "使用魔法的下划线符号,您可以通过向图构造函数传递一个名为 `layout_title_text` 的关键字参数和传递 `go.Scatter` 构造函数的关键字参数 `line_color`。" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import plotly.graph_objects as go\n", "\n", "fig = go.Figure(\n", " data=[go.Scatter(y=[1, 3, 2], line_color=\"crimson\")],\n", " layout_title_text=\"A Graph Objects Figure With Magic Underscore Notation\"\n", ")\n", "\n", "fig.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "整个图对象 API 都支持魔法下划线表示法,它通常可以显著地简化涉及深度嵌套属性的操作。\n", "\n", "## 更新轨迹\n", "图对象支持 {meth}`update_trace` 方法,该方法可用于更新图的一个或多个轨迹的多个嵌套属性。\n", "\n", "为了展示一些示例,将从包含横跨两个子图的条形和散点轨迹的图开始。" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from plotly.subplots import make_subplots\n", "\n", "fig = make_subplots(rows=1, cols=2)\n", "fig.add_scatter(y=[4, 2, 3.5], mode=\"markers\",\n", " marker=dict(size=20, color=\"LightSeaGreen\"),\n", " name=\"a\", row=1, col=1)\n", "\n", "fig.add_bar(y=[2, 1, 3],\n", " marker=dict(color=\"MediumPurple\"),\n", " name=\"b\", row=1, col=1)\n", "\n", "fig.add_scatter(y=[2, 3.5, 4], mode=\"markers\",\n", " marker=dict(size=20, color=\"MediumPurple\"),\n", " name=\"c\", row=1, col=2)\n", "\n", "fig.add_bar(y=[1, 3, 2],\n", " marker=dict(color=\"LightSeaGreen\"),\n", " name=\"d\", row=1, col=2)\n", "\n", "fig.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "注意 `scatter` 轨迹和 `bar` 轨迹都有 `marker.color` 属性来控制它们的颜色。下面是使用 {meth}`update_trace` 修改所有轨迹颜色的示例。" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from plotly.subplots import make_subplots\n", "\n", "fig = make_subplots(rows=1, cols=2)\n", "\n", "fig.add_scatter(y=[4, 2, 3.5], mode=\"markers\",\n", " marker=dict(size=20, color=\"LightSeaGreen\"),\n", " name=\"a\", row=1, col=1)\n", "\n", "fig.add_bar(y=[2, 1, 3],\n", " marker=dict(color=\"MediumPurple\"),\n", " name=\"b\", row=1, col=1)\n", "\n", "fig.add_scatter(y=[2, 3.5, 4], mode=\"markers\",\n", " marker=dict(size=20, color=\"MediumPurple\"),\n", " name=\"c\", row=1, col=2)\n", "\n", "fig.add_bar(y=[1, 3, 2],\n", " marker=dict(color=\"LightSeaGreen\"),\n", " name=\"d\", row=1, col=2)\n", "\n", "fig.update_traces(marker=dict(color=\"RoyalBlue\"))\n", "\n", "fig.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "{meth}`update_trace` 方法支持 `selector` 参数来控制应该更新哪些轨迹。只有具有匹配选择器属性的轨迹才会被更新。下面是使用选择器只更新条轨迹颜色的例子。" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from plotly.subplots import make_subplots\n", "\n", "fig = make_subplots(rows=1, cols=2)\n", "\n", "fig.add_scatter(y=[4, 2, 3.5], mode=\"markers\",\n", " marker=dict(size=20, color=\"LightSeaGreen\"),\n", " name=\"a\", row=1, col=1)\n", "\n", "fig.add_bar(y=[2, 1, 3],\n", " marker=dict(color=\"MediumPurple\"),\n", " name=\"b\", row=1, col=1)\n", "\n", "fig.add_scatter(y=[2, 3.5, 4], mode=\"markers\",\n", " marker=dict(size=20, color=\"MediumPurple\"),\n", " name=\"c\", row=1, col=2)\n", "\n", "fig.add_bar(y=[1, 3, 2],\n", " marker=dict(color=\"LightSeaGreen\"),\n", " name=\"d\", row=1, col=2)\n", "\n", "fig.update_traces(marker=dict(color=\"RoyalBlue\"),\n", " selector=dict(type=\"bar\"))\n", "\n", "fig.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "魔法下划线表示法可以在选择器中用于匹配嵌套属性。下面是更新所有被正式着色为 `\"MediumPurple\"` 的轨迹颜色的例子。" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from plotly.subplots import make_subplots\n", "\n", "fig = make_subplots(rows=1, cols=2)\n", "\n", "fig.add_scatter(y=[4, 2, 3.5], mode=\"markers\",\n", " marker=dict(size=20, color=\"LightSeaGreen\"),\n", " name=\"a\", row=1, col=1)\n", "\n", "fig.add_bar(y=[2, 1, 3],\n", " marker=dict(color=\"MediumPurple\"),\n", " name=\"b\", row=1, col=1)\n", "\n", "fig.add_scatter(y=[2, 3.5, 4], mode=\"markers\",\n", " marker=dict(size=20, color=\"MediumPurple\"),\n", " name=\"c\", row=1, col=2)\n", "\n", "fig.add_bar(y=[1, 3, 2],\n", " marker=dict(color=\"LightSeaGreen\"),\n", " name=\"d\", row=1, col=2)\n", "\n", "fig.update_traces(marker_color=\"RoyalBlue\",\n", " selector=dict(marker_color=\"MediumPurple\"))\n", "\n", "fig.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "对于带有子图的图,{meth}`update_trace` 方法还支持 `row` 和 `col` 参数来控制应该更新哪些轨迹。只会更新指定子图行和列中的轨迹。下面是更新第二个子图列中所有轨迹颜色的示例。" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from plotly.subplots import make_subplots\n", "\n", "fig = make_subplots(rows=1, cols=2)\n", "\n", "fig.add_scatter(y=[4, 2, 3.5], mode=\"markers\",\n", " marker=dict(size=20, color=\"LightSeaGreen\"),\n", " name=\"a\", row=1, col=1)\n", "\n", "fig.add_bar(y=[2, 1, 3],\n", " marker=dict(color=\"MediumPurple\"),\n", " name=\"b\", row=1, col=1)\n", "\n", "fig.add_scatter(y=[2, 3.5, 4], mode=\"markers\",\n", " marker=dict(size=20, color=\"MediumPurple\"),\n", " name=\"c\", row=1, col=2)\n", "\n", "fig.add_bar(y=[1, 3, 2],\n", " marker=dict(color=\"LightSeaGreen\"),\n", " name=\"d\", row=1, col=2)\n", "\n", "fig.update_traces(marker=dict(color=\"RoyalBlue\"),\n", " col=2)\n", "\n", "fig.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "{meth}`update_trace` 方法还可以用于由图工厂或 Plotly Express 生成的图。下面是将 Plotly Express 生成的回归线更新为虚线的示例。" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "import plotly.express as px\n", "\n", "df = px.data.iris()\n", "\n", "fig = px.scatter(df, x=\"sepal_width\", y=\"sepal_length\", color=\"species\",\n", " facet_col=\"species\", trendline=\"ols\", title=\"Using update_traces() With Plotly Express Figures\")\n", "\n", "fig.update_traces(\n", " line=dict(dash=\"dot\", width=4),\n", " selector=dict(type=\"scatter\", mode=\"lines\"))\n", "\n", "fig.show()" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3.10.4 ('tvmx': conda)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.4" }, "orig_nbformat": 4, "vscode": { "interpreter": { "hash": "e579259ee6098e2b9319de590d145b4b096774fe457bdf04260e3ba5c171e887" } } }, "nbformat": 4, "nbformat_minor": 2 }