From 9a26a63f4dd67722f82aaa7ad716559699a5fdff Mon Sep 17 00:00:00 2001 From: Liam Connors <connorsl@tcd.ie> Date: Thu, 20 Mar 2025 12:38:18 -0400 Subject: [PATCH 01/12] Add rename --- .circleci/config.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 3b36cc4802..14b14a0230 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -61,9 +61,9 @@ commands: cd js npm ci npm run build - + - when: - condition: + condition: not: equal: - <<parameters.pandas_version>> @@ -315,6 +315,8 @@ jobs: name: Install dependencies command: | cd doc + sudo apt-get update + sudo apt-get install rename curl -LsSf https://astral.sh/uv/install.sh | sh uv venv source .venv/bin/activate From 591f6a930c6927da65c9bfdcb1e00013e6705bd0 Mon Sep 17 00:00:00 2001 From: Liam Connors <connorsl@tcd.ie> Date: Thu, 3 Apr 2025 12:59:59 -0400 Subject: [PATCH 02/12] Remove deprecated append_trace from docs --- doc/python/3d-axes.md | 4 ++-- doc/python/histograms.md | 18 +++++++++--------- doc/python/horizontal-bar-charts.md | 14 +++++++------- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/doc/python/3d-axes.md b/doc/python/3d-axes.md index b6ec1d8d3e..e6ea841403 100644 --- a/doc/python/3d-axes.md +++ b/doc/python/3d-axes.md @@ -6,7 +6,7 @@ jupyter: extension: .md format_name: markdown format_version: '1.3' - jupytext_version: 1.15.1 + jupytext_version: 1.16.4 kernelspec: display_name: Python 3 (ipykernel) language: python @@ -114,7 +114,7 @@ fig = make_subplots(rows=2, cols=2, print_grid=False) for i in [1,2]: for j in [1,2]: - fig.append_trace( + fig.add_trace( go.Mesh3d( x=(60*np.random.randn(N)), y=(25*np.random.randn(N)), diff --git a/doc/python/histograms.md b/doc/python/histograms.md index 78eab47193..aca2c25b3d 100644 --- a/doc/python/histograms.md +++ b/doc/python/histograms.md @@ -6,9 +6,9 @@ jupyter: extension: .md format_name: markdown format_version: '1.3' - jupytext_version: 1.14.1 + jupytext_version: 1.16.4 kernelspec: - display_name: Python 3 + display_name: Python 3 (ipykernel) language: python name: python3 language_info: @@ -20,7 +20,7 @@ jupyter: name: python nbconvert_exporter: python pygments_lexer: ipython3 - version: 3.8.8 + version: 3.11.10 plotly: description: How to make Histograms in Python with Plotly. display_as: statistical @@ -438,12 +438,12 @@ trace5 = go.Histogram(x=x, autobinx = False ) -fig.append_trace(trace0, 1, 1) -fig.append_trace(trace1, 1, 2) -fig.append_trace(trace2, 2, 1) -fig.append_trace(trace3, 2, 2) -fig.append_trace(trace4, 3, 1) -fig.append_trace(trace5, 3, 2) +fig.add_trace(trace0, 1, 1) +fig.add_trace(trace1, 1, 2) +fig.add_trace(trace2, 2, 1) +fig.add_trace(trace3, 2, 2) +fig.add_trace(trace4, 3, 1) +fig.add_trace(trace5, 3, 2) fig.show() ``` diff --git a/doc/python/horizontal-bar-charts.md b/doc/python/horizontal-bar-charts.md index ae9b02e3d3..9454b5f07b 100644 --- a/doc/python/horizontal-bar-charts.md +++ b/doc/python/horizontal-bar-charts.md @@ -5,10 +5,10 @@ jupyter: text_representation: extension: .md format_name: markdown - format_version: '1.1' - jupytext_version: 1.1.1 + format_version: '1.3' + jupytext_version: 1.16.4 kernelspec: - display_name: Python 3 + display_name: Python 3 (ipykernel) language: python name: python3 language_info: @@ -20,7 +20,7 @@ jupyter: name: python nbconvert_exporter: python pygments_lexer: ipython3 - version: 3.6.7 + version: 3.11.10 plotly: description: How to make horizontal bar charts in Python with Plotly. display_as: basic @@ -239,7 +239,7 @@ x = ['Japan', 'United Kingdom', 'Canada', 'Netherlands', fig = make_subplots(rows=1, cols=2, specs=[[{}, {}]], shared_xaxes=True, shared_yaxes=False, vertical_spacing=0.001) -fig.append_trace(go.Bar( +fig.add_trace(go.Bar( x=y_saving, y=x, marker=dict( @@ -252,7 +252,7 @@ fig.append_trace(go.Bar( orientation='h', ), 1, 1) -fig.append_trace(go.Scatter( +fig.add_trace(go.Scatter( x=y_net_worth, y=x, mode='lines+markers', line_color='rgb(128, 0, 128)', @@ -335,4 +335,4 @@ fig.show() ### Reference -See more examples of bar charts and styling options [here](https://plotly.com/python/bar-charts/).<br> See https://plotly.com/python/reference/bar/ for more information and chart attribute options! \ No newline at end of file +See more examples of bar charts and styling options [here](https://plotly.com/python/bar-charts/).<br> See https://plotly.com/python/reference/bar/ for more information and chart attribute options! From a50bc3ef34fd697adb64104ac5aaa9b7b7fea12a Mon Sep 17 00:00:00 2001 From: Liam Connors <connorsl@tcd.ie> Date: Thu, 3 Apr 2025 13:01:20 -0400 Subject: [PATCH 03/12] remove deprecated append_trace --- doc/python/subplots.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/doc/python/subplots.md b/doc/python/subplots.md index 6842a650b5..b5711ee5de 100644 --- a/doc/python/subplots.md +++ b/doc/python/subplots.md @@ -6,9 +6,9 @@ jupyter: extension: .md format_name: markdown format_version: '1.3' - jupytext_version: 1.14.1 + jupytext_version: 1.16.4 kernelspec: - display_name: Python 3 + display_name: Python 3 (ipykernel) language: python name: python3 language_info: @@ -20,7 +20,7 @@ jupyter: name: python nbconvert_exporter: python pygments_lexer: ipython3 - version: 3.8.8 + version: 3.11.10 plotly: description: How to make subplots in with Plotly's Python graphing library. Examples of stacked, custom-sized, gridded, and annotated subplots. @@ -80,17 +80,17 @@ import plotly.graph_objects as go fig = make_subplots(rows=3, cols=1) -fig.append_trace(go.Scatter( +fig.add_trace(go.Scatter( x=[3, 4, 5], y=[1000, 1100, 1200], ), row=1, col=1) -fig.append_trace(go.Scatter( +fig.add_trace(go.Scatter( x=[2, 3, 4], y=[100, 110, 120], ), row=2, col=1) -fig.append_trace(go.Scatter( +fig.add_trace(go.Scatter( x=[0, 1, 2], y=[10, 11, 12] ), row=3, col=1) From 7a230fb6184cca857be15600ad5ce47034485609 Mon Sep 17 00:00:00 2001 From: Liam Connors <connorsl@tcd.ie> Date: Wed, 9 Apr 2025 14:45:00 -0400 Subject: [PATCH 04/12] Create supported-colors.md --- doc/python/supported-colors.md | 148 +++++++++++++++++++++++++++++++++ 1 file changed, 148 insertions(+) create mode 100644 doc/python/supported-colors.md diff --git a/doc/python/supported-colors.md b/doc/python/supported-colors.md new file mode 100644 index 0000000000..f1aae8f82e --- /dev/null +++ b/doc/python/supported-colors.md @@ -0,0 +1,148 @@ +--- +jupyter: + jupytext: + notebook_metadata_filter: all + text_representation: + extension: .md + format_name: markdown + format_version: '1.3' + jupytext_version: 1.17.0 + kernelspec: + display_name: Python 3 (ipykernel) + 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.13.2 + plotly: + description: A list of supported named CSS Colors + display_as: file_settings + language: python + layout: base + name: Supported CSS Colors + order: 40 + page_type: example_index + permalink: python/css-colors/ + thumbnail: thumbnail/shape.jpg +--- + +# Supported CSS Colors + +Many properties in Plotly.py for configuring colors support named CSS colors. For example, marker colors: + +```python +import plotly.graph_objects as go + +fig = go.Figure([ + go.Bar( + x=['Jan', 'Feb', 'Mar', 'Apr'], + y=[20, 14, 25, 16], + name='Primary Product', + # Named CSS color + marker_color='indianred' + ) +]) + +fig.show() +``` + +The following CSS colors are supported in Plotly.py when a property accepts a named CSS color: + +```python hide_code=true +import plotly.graph_objects as go +import pandas as pd + +supported_colors = ["aliceblue", "antiquewhite", "aqua", "aquamarine", "azure", + "beige", "bisque", "black", "blanchedalmond", "blue", + "blueviolet", "brown", "burlywood", "cadetblue", + "chartreuse", "chocolate", "coral", "cornflowerblue", + "cornsilk", "crimson", "cyan", "darkblue", "darkcyan", + "darkgoldenrod", "darkgray", "darkgrey", "darkgreen", + "darkkhaki", "darkmagenta", "darkolivegreen", "darkorange", + "darkorchid", "darkred", "darksalmon", "darkseagreen", + "darkslateblue", "darkslategray", "darkslategrey", + "darkturquoise", "darkviolet", "deeppink", "deepskyblue", + "dimgray", "dimgrey", "dodgerblue", "firebrick", + "floralwhite", "forestgreen", "fuchsia", "gainsboro", + "ghostwhite", "gold", "goldenrod", "gray", "grey", "green", + "greenyellow", "honeydew", "hotpink", "indianred", "indigo", + "ivory", "khaki", "lavender", "lavenderblush", "lawngreen", + "lemonchiffon", "lightblue", "lightcoral", "lightcyan", + "lightgoldenrodyellow", "lightgray", "lightgrey", + "lightgreen", "lightpink", "lightsalmon", "lightseagreen", + "lightskyblue", "lightslategray", "lightslategrey", + "lightsteelblue", "lightyellow", "lime", "limegreen", + "linen", "magenta", "maroon", "mediumaquamarine", + "mediumblue", "mediumorchid", "mediumpurple", + "mediumseagreen", "mediumslateblue", "mediumspringgreen", + "mediumturquoise", "mediumvioletred", "midnightblue", + "mintcream", "mistyrose", "moccasin", "navajowhite", "navy", + "oldlace", "olive", "olivedrab", "orange", "orangered", + "orchid", "palegoldenrod", "palegreen", "paleturquoise", + "palevioletred", "papayawhip", "peachpuff", "peru", "pink", + "plum", "powderblue", "purple", "red", "rosybrown", + "royalblue", "rebeccapurple", "saddlebrown", "salmon", + "sandybrown", "seagreen", "seashell", "sienna", "silver", + "skyblue", "slateblue", "slategray", "slategrey", "snow", + "springgreen", "steelblue", "tan", "teal", "thistle", "tomato", + "turquoise", "violet", "wheat", "white", "whitesmoke", + "yellow", "yellowgreen"] + +def display_colors_as_shapes(color_names): + fig = go.Figure(layout=dict(title="Supported CSS Colors in Plotly.py")) + + for i, color in enumerate(color_names): + row, col = i // 5, i % 5 + x0, y0 = col * 1.2, -row * 1.2 + + fig.add_shape( + type="rect", + x0=x0, y0=y0, + x1=x0+1, y1=y0+1, + fillcolor=color, + line=dict(color="black", width=1), + ) + + fig.add_annotation( + x=x0+0.5, y=y0-0.1, + text=color, + showarrow=False, + font=dict(size=10) + ) + + height = ((len(color_names) // 5) + (1 if len(color_names) % 5 else 0)) * 120 + + fig.update_layout( + height=height, + width=800, + showlegend=False, + plot_bgcolor='rgba(0,0,0,0)', + margin=dict(l=50, r=50, t=50, b=50), + xaxis=dict( + showgrid=False, + zeroline=False, + showticklabels=False, + range=[-0.5, 6] + ), + yaxis=dict( + showgrid=False, + zeroline=False, + showticklabels=False, + scaleanchor="x", + scaleratio=1, + range=[-((len(color_names) // 5) + 1) * 1.2, 1.5] + ) + ) + + return fig + +fig = display_colors_as_shapes(supported_colors) +fig.show() +``` From 5040be6e230420e59e813fd07c1d440117c4b2f3 Mon Sep 17 00:00:00 2001 From: Liam Connors <connorsl@tcd.ie> Date: Wed, 9 Apr 2025 15:02:14 -0400 Subject: [PATCH 05/12] Update supported-colors.md --- doc/python/supported-colors.md | 164 +++++++++++++++++---------------- 1 file changed, 84 insertions(+), 80 deletions(-) diff --git a/doc/python/supported-colors.md b/doc/python/supported-colors.md index f1aae8f82e..2b6e07c240 100644 --- a/doc/python/supported-colors.md +++ b/doc/python/supported-colors.md @@ -60,89 +60,93 @@ import plotly.graph_objects as go import pandas as pd supported_colors = ["aliceblue", "antiquewhite", "aqua", "aquamarine", "azure", - "beige", "bisque", "black", "blanchedalmond", "blue", - "blueviolet", "brown", "burlywood", "cadetblue", - "chartreuse", "chocolate", "coral", "cornflowerblue", - "cornsilk", "crimson", "cyan", "darkblue", "darkcyan", - "darkgoldenrod", "darkgray", "darkgrey", "darkgreen", - "darkkhaki", "darkmagenta", "darkolivegreen", "darkorange", - "darkorchid", "darkred", "darksalmon", "darkseagreen", - "darkslateblue", "darkslategray", "darkslategrey", - "darkturquoise", "darkviolet", "deeppink", "deepskyblue", - "dimgray", "dimgrey", "dodgerblue", "firebrick", - "floralwhite", "forestgreen", "fuchsia", "gainsboro", - "ghostwhite", "gold", "goldenrod", "gray", "grey", "green", - "greenyellow", "honeydew", "hotpink", "indianred", "indigo", - "ivory", "khaki", "lavender", "lavenderblush", "lawngreen", - "lemonchiffon", "lightblue", "lightcoral", "lightcyan", - "lightgoldenrodyellow", "lightgray", "lightgrey", - "lightgreen", "lightpink", "lightsalmon", "lightseagreen", - "lightskyblue", "lightslategray", "lightslategrey", - "lightsteelblue", "lightyellow", "lime", "limegreen", - "linen", "magenta", "maroon", "mediumaquamarine", - "mediumblue", "mediumorchid", "mediumpurple", - "mediumseagreen", "mediumslateblue", "mediumspringgreen", - "mediumturquoise", "mediumvioletred", "midnightblue", - "mintcream", "mistyrose", "moccasin", "navajowhite", "navy", - "oldlace", "olive", "olivedrab", "orange", "orangered", - "orchid", "palegoldenrod", "palegreen", "paleturquoise", - "palevioletred", "papayawhip", "peachpuff", "peru", "pink", - "plum", "powderblue", "purple", "red", "rosybrown", - "royalblue", "rebeccapurple", "saddlebrown", "salmon", - "sandybrown", "seagreen", "seashell", "sienna", "silver", - "skyblue", "slateblue", "slategray", "slategrey", "snow", - "springgreen", "steelblue", "tan", "teal", "thistle", "tomato", - "turquoise", "violet", "wheat", "white", "whitesmoke", - "yellow", "yellowgreen"] - -def display_colors_as_shapes(color_names): - fig = go.Figure(layout=dict(title="Supported CSS Colors in Plotly.py")) - - for i, color in enumerate(color_names): - row, col = i // 5, i % 5 - x0, y0 = col * 1.2, -row * 1.2 - - fig.add_shape( - type="rect", - x0=x0, y0=y0, - x1=x0+1, y1=y0+1, - fillcolor=color, - line=dict(color="black", width=1), - ) - - fig.add_annotation( - x=x0+0.5, y=y0-0.1, - text=color, - showarrow=False, - font=dict(size=10) - ) - - height = ((len(color_names) // 5) + (1 if len(color_names) % 5 else 0)) * 120 + "beige", "bisque", "black", "blanchedalmond", "blue", + "blueviolet", "brown", "burlywood", "cadetblue", + "chartreuse", "chocolate", "coral", "cornflowerblue", + "cornsilk", "crimson", "cyan", "darkblue", "darkcyan", + "darkgoldenrod", "darkgray", "darkgrey", "darkgreen", + "darkkhaki", "darkmagenta", "darkolivegreen", "darkorange", + "darkorchid", "darkred", "darksalmon", "darkseagreen", + "darkslateblue", "darkslategray", "darkslategrey", + "darkturquoise", "darkviolet", "deeppink", "deepskyblue", + "dimgray", "dimgrey", "dodgerblue", "firebrick", + "floralwhite", "forestgreen", "fuchsia", "gainsboro", + "ghostwhite", "gold", "goldenrod", "gray", "grey", "green", + "greenyellow", "honeydew", "hotpink", "indianred", "indigo", + "ivory", "khaki", "lavender", "lavenderblush", "lawngreen", + "lemonchiffon", "lightblue", "lightcoral", "lightcyan", + "lightgoldenrodyellow", "lightgray", "lightgrey", + "lightgreen", "lightpink", "lightsalmon", "lightseagreen", + "lightskyblue", "lightslategray", "lightslategrey", + "lightsteelblue", "lightyellow", "lime", "limegreen", + "linen", "magenta", "maroon", "mediumaquamarine", + "mediumblue", "mediumorchid", "mediumpurple", + "mediumseagreen", "mediumslateblue", "mediumspringgreen", + "mediumturquoise", "mediumvioletred", "midnightblue", + "mintcream", "mistyrose", "moccasin", "navajowhite", "navy", + "oldlace", "olive", "olivedrab", "orange", "orangered", + "orchid", "palegoldenrod", "palegreen", "paleturquoise", + "palevioletred", "papayawhip", "peachpuff", "peru", "pink", + "plum", "powderblue", "purple", "red", "rosybrown", + "royalblue", "rebeccapurple", "saddlebrown", "salmon", + "sandybrown", "seagreen", "seashell", "sienna", "silver", + "skyblue", "slateblue", "slategray", "slategrey", "snow", + "springgreen", "steelblue", "tan", "teal", "thistle", "tomato", + "turquoise", "violet", "wheat", "white", "whitesmoke", + "yellow", "yellowgreen"] + +fig = go.Figure(layout=dict(title="Supported Named CSS Colors")) + +for i, color in enumerate(supported_colors): + row, col = i // 5, i % 5 + x0, y0 = col * 1.2, -row * 1.2 - fig.update_layout( - height=height, - width=800, - showlegend=False, - plot_bgcolor='rgba(0,0,0,0)', - margin=dict(l=50, r=50, t=50, b=50), - xaxis=dict( - showgrid=False, - zeroline=False, - showticklabels=False, - range=[-0.5, 6] - ), - yaxis=dict( - showgrid=False, - zeroline=False, - showticklabels=False, - scaleanchor="x", - scaleratio=1, - range=[-((len(color_names) // 5) + 1) * 1.2, 1.5] - ) + fig.add_shape( + type="rect", + x0=x0, y0=y0, + x1=x0+1, y1=y0+1, + fillcolor=color, + line=dict(color="black", width=1), ) - return fig + fig.add_annotation( + x=x0+0.5, y=y0-0.1, + text=color, + showarrow=False, + font=dict(size=10) + ) + +height = ((len(supported_colors) // 5) + (1 if len(color_names) % 5 else 0)) * 120 + +fig.update_layout( + height=height, + width=800, + showlegend=False, + plot_bgcolor='rgba(0,0,0,0)', + margin=dict(l=50, r=50, t=50, b=50), + xaxis=dict( + showgrid=False, + zeroline=False, + showticklabels=False, + range=[-0.5, 6] + ), + yaxis=dict( + showgrid=False, + zeroline=False, + showticklabels=False, + scaleanchor="x", + scaleratio=1, + range=[-((len(supported_colors) // 5) + 1) * 1.2, 1.5] + ) +) -fig = display_colors_as_shapes(supported_colors) fig.show() ``` + +```python + +``` + +```python + +``` From 8b166bdc7b1e8cbd06120dbe76ea8e8079c1db22 Mon Sep 17 00:00:00 2001 From: Liam Connors <connorsl@tcd.ie> Date: Wed, 9 Apr 2025 15:06:46 -0400 Subject: [PATCH 06/12] Update supported-colors.md --- doc/python/supported-colors.md | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/doc/python/supported-colors.md b/doc/python/supported-colors.md index 2b6e07c240..3c6be98ad4 100644 --- a/doc/python/supported-colors.md +++ b/doc/python/supported-colors.md @@ -106,7 +106,7 @@ for i, color in enumerate(supported_colors): x0=x0, y0=y0, x1=x0+1, y1=y0+1, fillcolor=color, - line=dict(color="black", width=1), + line=dict(color="black", width=0.2), ) fig.add_annotation( @@ -116,10 +116,8 @@ for i, color in enumerate(supported_colors): font=dict(size=10) ) -height = ((len(supported_colors) // 5) + (1 if len(color_names) % 5 else 0)) * 120 - fig.update_layout( - height=height, + height=((len(supported_colors) // 5) + (1 if len(color_names) % 5 else 0)) * 120, width=800, showlegend=False, plot_bgcolor='rgba(0,0,0,0)', @@ -142,11 +140,3 @@ fig.update_layout( fig.show() ``` - -```python - -``` - -```python - -``` From 7a4ffa402d7ea74685dcccb3a0fa27f0ecbb6134 Mon Sep 17 00:00:00 2001 From: Liam Connors <connorsl@tcd.ie> Date: Wed, 9 Apr 2025 15:12:21 -0400 Subject: [PATCH 07/12] Update supported-colors.md --- doc/python/supported-colors.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/python/supported-colors.md b/doc/python/supported-colors.md index 3c6be98ad4..9c825b3c97 100644 --- a/doc/python/supported-colors.md +++ b/doc/python/supported-colors.md @@ -46,7 +46,7 @@ fig = go.Figure([ y=[20, 14, 25, 16], name='Primary Product', # Named CSS color - marker_color='indianred' + marker_color='royalblue' ) ]) From a07705a02ad7506fe63a4ab90421fe3743bd8d3b Mon Sep 17 00:00:00 2001 From: Liam Connors <connorsl@tcd.ie> Date: Wed, 9 Apr 2025 15:49:09 -0400 Subject: [PATCH 08/12] Update supported-colors.md --- doc/python/supported-colors.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/python/supported-colors.md b/doc/python/supported-colors.md index 9c825b3c97..d9510b58c5 100644 --- a/doc/python/supported-colors.md +++ b/doc/python/supported-colors.md @@ -117,7 +117,7 @@ for i, color in enumerate(supported_colors): ) fig.update_layout( - height=((len(supported_colors) // 5) + (1 if len(color_names) % 5 else 0)) * 120, + height=((len(supported_colors) // 5) + (1 if len(supported_colors) % 5 else 0)) * 120, width=800, showlegend=False, plot_bgcolor='rgba(0,0,0,0)', From 79a0e0e8c596bdcf719086f61166442c72f65853 Mon Sep 17 00:00:00 2001 From: Liam Connors <liam@plot.ly> Date: Thu, 10 Apr 2025 14:53:36 -0400 Subject: [PATCH 09/12] Update doc/python/supported-colors.md --- doc/python/supported-colors.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/python/supported-colors.md b/doc/python/supported-colors.md index d9510b58c5..52820ef3af 100644 --- a/doc/python/supported-colors.md +++ b/doc/python/supported-colors.md @@ -53,7 +53,7 @@ fig = go.Figure([ fig.show() ``` -The following CSS colors are supported in Plotly.py when a property accepts a named CSS color: +These colors are supported in Plotly.py when a property accepts a [named CSS colors](https://developer.mozilla.org/en-US/docs/Web/CSS/named-color). ```python hide_code=true import plotly.graph_objects as go From c8b38f41c504e142139f1146caa9ec934e9b5164 Mon Sep 17 00:00:00 2001 From: Liam Connors <liam@plot.ly> Date: Thu, 10 Apr 2025 14:54:54 -0400 Subject: [PATCH 10/12] Update doc/python/supported-colors.md --- doc/python/supported-colors.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/python/supported-colors.md b/doc/python/supported-colors.md index 52820ef3af..53fd7b3aec 100644 --- a/doc/python/supported-colors.md +++ b/doc/python/supported-colors.md @@ -53,7 +53,7 @@ fig = go.Figure([ fig.show() ``` -These colors are supported in Plotly.py when a property accepts a [named CSS colors](https://developer.mozilla.org/en-US/docs/Web/CSS/named-color). +These colors are supported in Plotly.py when a property accepts a [named CSS color](https://developer.mozilla.org/en-US/docs/Web/CSS/named-color). ```python hide_code=true import plotly.graph_objects as go From 2c649d2fd3ec8a19bed79ead56db4a2452fcc1d2 Mon Sep 17 00:00:00 2001 From: Rob Letzler <22990670+rl-utility-man@users.noreply.github.com> Date: Fri, 11 Apr 2025 22:12:21 -0400 Subject: [PATCH 11/12] corrected a label from Canada to Oceania Addressing issue #5129 --- doc/python/bar-charts.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/python/bar-charts.md b/doc/python/bar-charts.md index f16955a93b..543b1563e3 100644 --- a/doc/python/bar-charts.md +++ b/doc/python/bar-charts.md @@ -124,7 +124,7 @@ import plotly.express as px df = px.data.gapminder().query("continent == 'Oceania'") fig = px.bar(df, x='year', y='pop', hover_data=['lifeExp', 'gdpPercap'], color='country', - labels={'pop':'population of Canada'}, height=400) + labels={'pop':'population of Oceania'}, height=400) fig.show() ``` From 5a9b1fb256890e837c241c52ff1cd88c9d2108b3 Mon Sep 17 00:00:00 2001 From: Rob Letzler <22990670+rl-utility-man@users.noreply.github.com> Date: Fri, 18 Apr 2025 14:26:23 -0400 Subject: [PATCH 12/12] Applying changes that #4994 made to "main" to "doc-prod" --- doc/python/horizontal-bar-charts.md | 71 +++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/doc/python/horizontal-bar-charts.md b/doc/python/horizontal-bar-charts.md index 9454b5f07b..3a5070f9bc 100644 --- a/doc/python/horizontal-bar-charts.md +++ b/doc/python/horizontal-bar-charts.md @@ -217,6 +217,77 @@ fig.update_layout(annotations=annotations) fig.show() ``` +### Diverging Bar (or Butterfly) Chart + +Diverging bar charts show counts of positive outcomes or sentiments to the right of zero and counts of negative outcomes to the left of zero, allowing the reader to easily spot areas of excellence and concern. This example allows the reader of the graph to infer the number of people offering a neutral response because the neutral category, which is left implicit, would make the responses add to 100%. + +```python +import plotly.graph_objects as go +import pandas as pd + + +df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/refs/heads/master/gss_2002_5_pt_likert.csv') + +df.rename(columns={'Unnamed: 0':"Category"}, inplace=True) + +#achieve the diverging effect by putting a negative sign on the "disagree" answers +for v in ["Disagree","Strongly Disagree"]: + df[v]=df[v]*-1 + +fig = go.Figure() +# this color palette conveys meaning: blues for positive, red and orange for negative +color_by_category={ + "Strongly Agree":'darkblue', + "Agree":'lightblue', + "Disagree":'orange', + "Strongly Disagree":'red', +} + + +# We want the legend to be ordered in the same order that the categories appear, left to right -- +# which is different from the order in which we have to add the traces to the figure. +# since we need to create the "somewhat" traces before the "strongly" traces to display +# the segments in the desired order +legend_rank_by_category={ + "Strongly Disagree":1, + "Disagree":2, + "Agree":3, + "Strongly Agree":4, +} +# Add bars for each category +for col in ["Disagree","Strongly Disagree","Agree","Strongly Agree"]: + fig.add_trace(go.Bar( + y=df["Category"], + x=df[col], + name=col, + orientation='h', + marker=dict(color=color_by_category[col]), + legendrank=legend_rank_by_category[col] + )) + +fig.update_layout( + title="Reactions to statements from the 2002 General Social Survey:", + yaxis_title = "", + barmode='relative', # Allows bars to diverge from the center + plot_bgcolor="white", +) + +fig.update_xaxes( + title="Percent of Responses", + zeroline=True, # Ensure there's a zero line for divergence + zerolinecolor="black", + # use array tick mode to show that the counts to the left of zero are still positive. + # this is hard coded; generalize this if you plan to create a function that takes unknown or widely varying data + tickmode = 'array', + tickvals = [-50, 0, 50, 100], + ticktext = [50, 0, 50, 100] +) + +fig.show() + +``` + + ### Bar Chart with Line Plot ```python