From 7e342fe37a83602b8fc70e80ce923bf5d0c1b225 Mon Sep 17 00:00:00 2001 From: SimaRaha Date: Sat, 25 Jan 2025 10:28:54 -0500 Subject: [PATCH 01/14] Update horizontal-bar-charts.md An example of a Horizontal Bar Chart (Facet) is added. --- doc/python/horizontal-bar-charts.md | 38 ++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/doc/python/horizontal-bar-charts.md b/doc/python/horizontal-bar-charts.md index ae9b02e3d30..7cd988f48ee 100644 --- a/doc/python/horizontal-bar-charts.md +++ b/doc/python/horizontal-bar-charts.md @@ -109,6 +109,42 @@ fig.add_trace(go.Bar( fig.update_layout(barmode='stack') fig.show() ``` +# 1. Example Horizontal Bar Chart (Facet) +import pandas as pd + +data = { + "Quarter": ["Q1", "Q2", "Q3", "Q4"] * 3, + "Region": ["North", "North", "North", "North", "South", "South", "South", "South", "West", "West", "West", "West"], + "Outcome": [150, 200, 250, 300, 120, 180, 240, 310, 100, 150, 220, 280] +} +df = pd.DataFrame(data) + +import plotly.express as px + +fig = px.bar( + df, + x="Outcome", + y="Region", + orientation="h", + facet_col="Quarter", + title="Quarterly Number of Patients Served by Region", + labels={"Outcome": "Patients Served", "Region": "Region"} +) + +fig.update_layout( + height=400, + title_font_size=16, + title_x=0.5, + showlegend=False, # Remove legend for simplicity + margin=dict(t=50, l=50, r=50, b=50) # Adjust margins +) + +fig.for_each_annotation(lambda a: a.update(text=a.text.split("=")[-1])) +# Remove duplicate y-axis labels +fig.for_each_yaxis(lambda axis: axis.update(title="Region")) +fig.for_each_xaxis(lambda axis: axis.update(title=None)) + +fig.show() ### Color Palette for Bar Chart @@ -335,4 +371,4 @@ fig.show() ### Reference -See more examples of bar charts and styling options [here](https://plotly.com/python/bar-charts/).
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/).
See https://plotly.com/python/reference/bar/ for more information and chart attribute options! From eec9e83a7abb9cdc18c928c99cc311df07805a3e Mon Sep 17 00:00:00 2001 From: Rob Letzler <22990670+rl-utility-man@users.noreply.github.com> Date: Sun, 26 Jan 2025 21:40:08 -0500 Subject: [PATCH 02/14] added explanation --- doc/python/horizontal-bar-charts.md | 30 +++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/doc/python/horizontal-bar-charts.md b/doc/python/horizontal-bar-charts.md index 7cd988f48ee..f34298bdb4f 100644 --- a/doc/python/horizontal-bar-charts.md +++ b/doc/python/horizontal-bar-charts.md @@ -109,8 +109,15 @@ fig.add_trace(go.Bar( fig.update_layout(barmode='stack') fig.show() ``` -# 1. Example Horizontal Bar Chart (Facet) +### Small multiple horizontal bar charts show each component's size more clearly than a stacked bar + +Bar charts with multiple components pose a fundamental trade off between presenting the total clearly and presenting the component values clearly. This small multiples approach shows the component magnitudes clearly at the cost of slightly obscuring the totals. A stacked bar does the opposite. Small multiple bar charts often work better in a horizontal orientation; and are easy to create with the px.bar orientation and facet_col parameters. + + . + +``` import pandas as pd +import plotly.express as px data = { "Quarter": ["Q1", "Q2", "Q3", "Q4"] * 3, @@ -119,7 +126,6 @@ data = { } df = pd.DataFrame(data) -import plotly.express as px fig = px.bar( df, @@ -127,24 +133,28 @@ fig = px.bar( y="Region", orientation="h", facet_col="Quarter", - title="Quarterly Number of Patients Served by Region", + title="Number of Patients Served by Region and Quarter", labels={"Outcome": "Patients Served", "Region": "Region"} ) +## the section below is optional clean up to make this presentation ready + fig.update_layout( - height=400, - title_font_size=16, - title_x=0.5, - showlegend=False, # Remove legend for simplicity - margin=dict(t=50, l=50, r=50, b=50) # Adjust margins + height=400, #the Plotly default makes the bars awkwardly large; setting a height improves the display + showlegend=False, # the legend does not add anything ) +#remove up the default "facet_variable =" text from the title of each facet graph fig.for_each_annotation(lambda a: a.update(text=a.text.split("=")[-1])) -# Remove duplicate y-axis labels -fig.for_each_yaxis(lambda axis: axis.update(title="Region")) + +# Remove duplicate axis labels +fig.for_each_yaxis(lambda axis: axis.update(title=None)) fig.for_each_xaxis(lambda axis: axis.update(title=None)) +# add the one valuable axis label back in +fig.update_xaxes(title="Count", row=1, col=1) fig.show() +``` ### Color Palette for Bar Chart From e8eb91838e682e155c572f8a3c1869c43da46de6 Mon Sep 17 00:00:00 2001 From: Rob Letzler <22990670+rl-utility-man@users.noreply.github.com> Date: Sun, 26 Jan 2025 21:45:38 -0500 Subject: [PATCH 03/14] added a cross reference to facet plots --- doc/python/facet-plots.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/python/facet-plots.md b/doc/python/facet-plots.md index 5d0f629b2ea..ff700730017 100644 --- a/doc/python/facet-plots.md +++ b/doc/python/facet-plots.md @@ -54,6 +54,8 @@ fig.show() ### Bar Chart Row Facets +There is a similar horizontal, faceted bar chart in the [horizontal bar documentation](/python/horizontal-bar-charts/#Small-multiple-horizontal-bar-charts-show-each-component's-size-more-clearly-than-a-stacked-bar) + ```python import plotly.express as px df = px.data.tips() From ceb1b1799241a8d6570afb52b0d927c865992895 Mon Sep 17 00:00:00 2001 From: Rob Letzler <22990670+rl-utility-man@users.noreply.github.com> Date: Sun, 26 Jan 2025 21:46:20 -0500 Subject: [PATCH 04/14] added a cross reference to facet plots --- doc/python/facet-plots.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/python/facet-plots.md b/doc/python/facet-plots.md index ff700730017..7a79ea06c2d 100644 --- a/doc/python/facet-plots.md +++ b/doc/python/facet-plots.md @@ -54,7 +54,7 @@ fig.show() ### Bar Chart Row Facets -There is a similar horizontal, faceted bar chart in the [horizontal bar documentation](/python/horizontal-bar-charts/#Small-multiple-horizontal-bar-charts-show-each-component's-size-more-clearly-than-a-stacked-bar) +There is a more presentation-ready horizontal, faceted bar chart in the [horizontal bar documentation](/python/horizontal-bar-charts/#Small-multiple-horizontal-bar-charts-show-each-component's-size-more-clearly-than-a-stacked-bar) ```python import plotly.express as px From 84c7f4a476f03217071025a1504764fb53891445 Mon Sep 17 00:00:00 2001 From: Aidan Feldman Date: Tue, 22 Apr 2025 11:38:14 -0400 Subject: [PATCH 05/14] Elaborate on difference between Plotly Express and Graph Objects functions --- doc/python/graph-objects.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/doc/python/graph-objects.md b/doc/python/graph-objects.md index 936ea6d6960..fca2c41f2e7 100644 --- a/doc/python/graph-objects.md +++ b/doc/python/graph-objects.md @@ -68,7 +68,9 @@ Note that the figures produced by Plotly Express **in a single function-call** a The figures produced by Plotly Express can always be built from the ground up using graph objects, but this approach typically takes **5-100 lines of code rather than 1**. -Here is a simple example of how to produce the same figure object from the same data, once with Plotly Express and once without. The data in this example is in "long form" but [Plotly Express also accepts data in "wide form"](/python/wide-form/) and the line-count savings from Plotly Express over graph objects are comparable. More complex figures such as [sunbursts](/python/sunburst-charts/), [parallel coordinates](/python/parallel-coordinates-plot/), [facet plots](/python/facet-plots/) or [animations](/python/animations/) require many more lines of figure-specific graph objects code, whereas switching from one representation to another with Plotly Express usually involves changing just a few characters. +Here is a simple example of how to produce the same figure object from the same data, once with Plotly Express and once without. Note that [Plotly Express functions](/python-api-reference/plotly.express.html) like [`px.bar()`](/python/bar-charts/) accept a DataFrame and names of columns as the `x` and `y` arguments, while [Graph Objects functions](/python-api-reference/plotly.graph_objects.html) like [`go.Bar()`](/python/bar-charts/#basic-bar-charts-with-plotlygraphobjects) require the values to be passed to the `x` and `y` as a Series/list. + +The data in this example is in "long form" but [Plotly Express also accepts data in "wide form"](/python/wide-form/) and the line-count savings from Plotly Express over graph objects are comparable. More complex figures such as [sunbursts](/python/sunburst-charts/), [parallel coordinates](/python/parallel-coordinates-plot/), [facet plots](/python/facet-plots/) or [animations](/python/animations/) require many more lines of figure-specific graph objects code, whereas switching from one representation to another with Plotly Express usually involves changing just a few characters. ```python import pandas as pd From 7cafb628c6339be4bec16cebf191f0e44efaebb8 Mon Sep 17 00:00:00 2001 From: Aidan Feldman Date: Tue, 29 Apr 2025 22:21:53 -0400 Subject: [PATCH 06/14] tweaking of Plotly Express vs. Graph Objects wording Co-authored-by: Emily KL <4672118+emilykl@users.noreply.github.com> --- doc/python/graph-objects.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/python/graph-objects.md b/doc/python/graph-objects.md index fca2c41f2e7..878b36d6bfc 100644 --- a/doc/python/graph-objects.md +++ b/doc/python/graph-objects.md @@ -68,7 +68,7 @@ Note that the figures produced by Plotly Express **in a single function-call** a The figures produced by Plotly Express can always be built from the ground up using graph objects, but this approach typically takes **5-100 lines of code rather than 1**. -Here is a simple example of how to produce the same figure object from the same data, once with Plotly Express and once without. Note that [Plotly Express functions](/python-api-reference/plotly.express.html) like [`px.bar()`](/python/bar-charts/) accept a DataFrame and names of columns as the `x` and `y` arguments, while [Graph Objects functions](/python-api-reference/plotly.graph_objects.html) like [`go.Bar()`](/python/bar-charts/#basic-bar-charts-with-plotlygraphobjects) require the values to be passed to the `x` and `y` as a Series/list. +Here is a simple example of how to produce the same figure object from the same data, once with Plotly Express and once without. Note that [Plotly Express functions](/python-api-reference/plotly.express.html) like [`px.bar()`](/python/bar-charts/) can accept a DataFrame as their first argument with column names passed to the `x` and `y` arguments, while [Graph Objects functions](/python-api-reference/plotly.graph_objects.html) like [`go.Bar()`](/python/bar-charts/#basic-bar-charts-with-plotlygraphobjects) require the data values to be passed directly to the `x` and `y` arguments as a tuple, list, NumPy array, or Pandas Series. The data in this example is in "long form" but [Plotly Express also accepts data in "wide form"](/python/wide-form/) and the line-count savings from Plotly Express over graph objects are comparable. More complex figures such as [sunbursts](/python/sunburst-charts/), [parallel coordinates](/python/parallel-coordinates-plot/), [facet plots](/python/facet-plots/) or [animations](/python/animations/) require many more lines of figure-specific graph objects code, whereas switching from one representation to another with Plotly Express usually involves changing just a few characters. From b12a4e26fef632100b96bbc172b2798ba1a8ace4 Mon Sep 17 00:00:00 2001 From: Rob Letzler <22990670+rl-utility-man@users.noreply.github.com> Date: Fri, 9 May 2025 15:46:45 -0400 Subject: [PATCH 07/14] replace rgb codes with CSS colors including plotly recommended colors --- doc/python/horizontal-bar-charts.md | 50 ++++++++++++++--------------- 1 file changed, 24 insertions(+), 26 deletions(-) diff --git a/doc/python/horizontal-bar-charts.md b/doc/python/horizontal-bar-charts.md index 3a5070f9bc8..09cdb982a1c 100644 --- a/doc/python/horizontal-bar-charts.md +++ b/doc/python/horizontal-bar-charts.md @@ -91,8 +91,8 @@ fig.add_trace(go.Bar( name='SF Zoo', orientation='h', marker=dict( - color='rgba(246, 78, 139, 0.6)', - line=dict(color='rgba(246, 78, 139, 1.0)', width=3) + color='hotpink', + line=dict(color='deeppink', width=3) ) )) fig.add_trace(go.Bar( @@ -101,8 +101,8 @@ fig.add_trace(go.Bar( name='LA Zoo', orientation='h', marker=dict( - color='rgba(58, 71, 80, 0.6)', - line=dict(color='rgba(58, 71, 80, 1.0)', width=3) + color='dimgray', + line=dict(color='black', width=3) ) )) @@ -118,10 +118,8 @@ import plotly.graph_objects as go top_labels = ['Strongly
agree', 'Agree', 'Neutral', 'Disagree', 'Strongly
disagree'] -colors = ['rgba(38, 24, 74, 0.8)', 'rgba(71, 58, 131, 0.8)', - 'rgba(122, 120, 168, 0.8)', 'rgba(164, 163, 204, 0.85)', - 'rgba(190, 192, 213, 1)'] - +colors = ['DarkBlue', 'MediumBlue', 'cyan', 'mediumpurple', 'thistle'] +#, 'silver' x_data = [[21, 30, 21, 16, 12], [24, 31, 19, 15, 11], [27, 26, 23, 11, 13], @@ -142,7 +140,7 @@ for i in range(0, len(x_data[0])): orientation='h', marker=dict( color=colors[i], - line=dict(color='rgb(248, 248, 249)', width=1) + line=dict(color='ghostwhite', width=1) ) )) @@ -161,8 +159,8 @@ fig.update_layout( zeroline=False, ), barmode='stack', - paper_bgcolor='rgb(248, 248, 255)', - plot_bgcolor='rgb(248, 248, 255)', + paper_bgcolor='lavenderblush', + plot_bgcolor='lavenderblush', margin=dict(l=120, r=10, t=140, b=80), showlegend=False, ) @@ -176,14 +174,14 @@ for yd, xd in zip(y_data, x_data): xanchor='right', text=str(yd), font=dict(family='Arial', size=14, - color='rgb(67, 67, 67)'), + color='dimgray'), showarrow=False, align='right')) # labeling the first percentage of each bar (x_axis) annotations.append(dict(xref='x', yref='y', x=xd[0] / 2, y=yd, text=str(xd[0]) + '%', font=dict(family='Arial', size=14, - color='rgb(248, 248, 255)'), + color='white'), showarrow=False)) # labeling the first Likert scale (on the top) if yd == y_data[-1]: @@ -191,7 +189,7 @@ for yd, xd in zip(y_data, x_data): x=xd[0] / 2, y=1.1, text=top_labels[0], font=dict(family='Arial', size=14, - color='rgb(67, 67, 67)'), + color='dimgray'), showarrow=False)) space = xd[0] for i in range(1, len(xd)): @@ -200,7 +198,7 @@ for yd, xd in zip(y_data, x_data): x=space + (xd[i]/2), y=yd, text=str(xd[i]) + '%', font=dict(family='Arial', size=14, - color='rgb(248, 248, 255)'), + color=f"{'white'*(i<2)}{'black'*(i>=2)}"), showarrow=False)) # labeling the Likert scale if yd == y_data[-1]: @@ -208,7 +206,7 @@ for yd, xd in zip(y_data, x_data): x=space + (xd[i]/2), y=1.1, text=top_labels[i], font=dict(family='Arial', size=14, - color='rgb(67, 67, 67)'), + color='dimgray'), showarrow=False)) space += xd[i] @@ -314,9 +312,9 @@ fig.add_trace(go.Bar( x=y_saving, y=x, marker=dict( - color='rgba(50, 171, 96, 0.6)', + color='mediumseagreen', line=dict( - color='rgba(50, 171, 96, 1.0)', + color='seagreen', width=1), ), name='Household savings, percentage of household disposable income', @@ -326,7 +324,7 @@ fig.add_trace(go.Bar( fig.add_trace(go.Scatter( x=y_net_worth, y=x, mode='lines+markers', - line_color='rgb(128, 0, 128)', + line_color='purple', name='Household net worth, Million USD/capita', ), 1, 2) @@ -342,7 +340,7 @@ fig.update_layout( showgrid=False, showline=True, showticklabels=False, - linecolor='rgba(102, 102, 102, 0.8)', + linecolor='gray', linewidth=2, domain=[0, 0.85], ), @@ -364,8 +362,8 @@ fig.update_layout( ), legend=dict(x=0.029, y=1.038, font_size=10), margin=dict(l=100, r=20, t=70, b=70), - paper_bgcolor='rgb(248, 248, 255)', - plot_bgcolor='rgb(248, 248, 255)', + paper_bgcolor='lavenderblush', + plot_bgcolor='lavenderblush', ) annotations = [] @@ -380,14 +378,14 @@ for ydn, yd, xd in zip(y_nw, y_s, x): y=xd, x=ydn - 20000, text='{:,}'.format(ydn) + 'M', font=dict(family='Arial', size=12, - color='rgb(128, 0, 128)'), + color='purple'), showarrow=False)) # labeling the bar net worth annotations.append(dict(xref='x1', yref='y1', y=xd, x=yd + 3, text=str(yd) + '%', - font=dict(family='Arial', size=12, - color='rgb(50, 171, 96)'), + font=dict(family='Arial', size=16, + color='mediumseagreen'), showarrow=False)) # Source annotations.append(dict(xref='paper', yref='paper', @@ -396,7 +394,7 @@ annotations.append(dict(xref='paper', yref='paper', '(2015), Household savings (indicator), ' + 'Household net worth (indicator). doi: ' + '10.1787/cfc6f499-en (Accessed on 05 June 2015)', - font=dict(family='Arial', size=10, color='rgb(150,150,150)'), + font=dict(family='Arial', size=10, color='gray'), showarrow=False)) fig.update_layout(annotations=annotations) From c3b7ce1e9bcdeab225745d68ed6f760eb41598e3 Mon Sep 17 00:00:00 2001 From: Rob Letzler <22990670+rl-utility-man@users.noreply.github.com> Date: Fri, 16 May 2025 13:24:30 -0400 Subject: [PATCH 08/14] Apply suggestions from code review Co-authored-by: Liam Connors --- doc/python/horizontal-bar-charts.md | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/doc/python/horizontal-bar-charts.md b/doc/python/horizontal-bar-charts.md index f34298bdb4f..c040208a189 100644 --- a/doc/python/horizontal-bar-charts.md +++ b/doc/python/horizontal-bar-charts.md @@ -111,10 +111,7 @@ fig.show() ``` ### Small multiple horizontal bar charts show each component's size more clearly than a stacked bar -Bar charts with multiple components pose a fundamental trade off between presenting the total clearly and presenting the component values clearly. This small multiples approach shows the component magnitudes clearly at the cost of slightly obscuring the totals. A stacked bar does the opposite. Small multiple bar charts often work better in a horizontal orientation; and are easy to create with the px.bar orientation and facet_col parameters. - - . - +Bar charts with multiple components pose a fundamental trade off between presenting the total clearly and presenting the component values clearly. This small multiples approach shows the component magnitudes clearly at the cost of slightly obscuring the totals. A stacked bar does the opposite. Small multiple bar charts often work better in a horizontal orientation; and are easy to create with the px.bar orientation and facet_col parameters. ``` import pandas as pd import plotly.express as px @@ -144,7 +141,7 @@ fig.update_layout( showlegend=False, # the legend does not add anything ) -#remove up the default "facet_variable =" text from the title of each facet graph +# remove the default "facet_variable =" text from the title of each facet graph fig.for_each_annotation(lambda a: a.update(text=a.text.split("=")[-1])) # Remove duplicate axis labels From cb22826d74a5340762d6000974366f6fb2642bb3 Mon Sep 17 00:00:00 2001 From: Liam Connors Date: Tue, 20 May 2025 11:31:03 -0400 Subject: [PATCH 09/14] Change docstring to not break on hyphens --- plotly/express/_doc.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/plotly/express/_doc.py b/plotly/express/_doc.py index 8754e5265b3..59faac4c0b3 100644 --- a/plotly/express/_doc.py +++ b/plotly/express/_doc.py @@ -612,7 +612,12 @@ def make_docstring(fn, override_dict=None, append_dict=None): override_dict = {} if override_dict is None else override_dict append_dict = {} if append_dict is None else append_dict - tw = TextWrapper(width=75, initial_indent=" ", subsequent_indent=" ") + tw = TextWrapper( + width=75, + initial_indent=" ", + subsequent_indent=" ", + break_on_hyphens=False, + ) result = (fn.__doc__ or "") + "\nParameters\n----------\n" for param in getfullargspec(fn)[0]: if override_dict.get(param): From 4de735732d4c3164d5f900b7886f21cded64f845 Mon Sep 17 00:00:00 2001 From: Rob Letzler <22990670+rl-utility-man@users.noreply.github.com> Date: Sat, 24 May 2025 21:33:30 -0400 Subject: [PATCH 10/14] switched from hex codes to CSS colors --- doc/python/dropdowns.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/python/dropdowns.md b/doc/python/dropdowns.md index 222b794e804..c43103a630f 100644 --- a/doc/python/dropdowns.md +++ b/doc/python/dropdowns.md @@ -365,27 +365,27 @@ fig.add_trace( go.Scatter(x=list(df.Date), y=list(df.High), name="High", - line=dict(color="#33CFA5"))) + line=dict(color="DarkBlue"))) fig.add_trace( go.Scatter(x=list(df.Date), y=[df.High.mean()] * len(df.index), name="High Average", visible=False, - line=dict(color="#33CFA5", dash="dash"))) + line=dict(color="DarkBlue", dash="dash"))) fig.add_trace( go.Scatter(x=list(df.Date), y=list(df.Low), name="Low", - line=dict(color="#F06A6A"))) + line=dict(color="Crimson"))) fig.add_trace( go.Scatter(x=list(df.Date), y=[df.Low.mean()] * len(df.index), name="Low Average", visible=False, - line=dict(color="#F06A6A", dash="dash"))) + line=dict(color="Crimson", dash="dash"))) # Add Annotations and Buttons high_annotations = [dict(x="2016-03-01", From 123c6b93d1ae385c57ba8e64d194ed4b1341beaa Mon Sep 17 00:00:00 2001 From: Rob Letzler <22990670+rl-utility-man@users.noreply.github.com> Date: Tue, 3 Jun 2025 19:17:52 -0400 Subject: [PATCH 11/14] deleted stray comment --- doc/python/horizontal-bar-charts.md | 1 - 1 file changed, 1 deletion(-) diff --git a/doc/python/horizontal-bar-charts.md b/doc/python/horizontal-bar-charts.md index 09cdb982a1c..04c57fd2104 100644 --- a/doc/python/horizontal-bar-charts.md +++ b/doc/python/horizontal-bar-charts.md @@ -119,7 +119,6 @@ top_labels = ['Strongly
agree', 'Agree', 'Neutral', 'Disagree', 'Strongly
disagree'] colors = ['DarkBlue', 'MediumBlue', 'cyan', 'mediumpurple', 'thistle'] -#, 'silver' x_data = [[21, 30, 21, 16, 12], [24, 31, 19, 15, 11], [27, 26, 23, 11, 13], From c754a260309bfe0ec9579c3e4f94debd2880bf12 Mon Sep 17 00:00:00 2001 From: Rob Letzler <22990670+rl-utility-man@users.noreply.github.com> Date: Sat, 7 Jun 2025 19:12:28 -0400 Subject: [PATCH 12/14] added Python decorator to the markdown --- doc/python/horizontal-bar-charts.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/python/horizontal-bar-charts.md b/doc/python/horizontal-bar-charts.md index 274e53010bb..1daf8c65051 100644 --- a/doc/python/horizontal-bar-charts.md +++ b/doc/python/horizontal-bar-charts.md @@ -112,7 +112,7 @@ fig.show() ### Small multiple horizontal bar charts show each component's size more clearly than a stacked bar Bar charts with multiple components pose a fundamental trade off between presenting the total clearly and presenting the component values clearly. This small multiples approach shows the component magnitudes clearly at the cost of slightly obscuring the totals. A stacked bar does the opposite. Small multiple bar charts often work better in a horizontal orientation; and are easy to create with the px.bar orientation and facet_col parameters. -``` +```python import pandas as pd import plotly.express as px From bd10f207b5c6fce173aae5fbbd2bdd0eb7a68e2d Mon Sep 17 00:00:00 2001 From: Rob Letzler <22990670+rl-utility-man@users.noreply.github.com> Date: Mon, 9 Jun 2025 17:10:32 -0400 Subject: [PATCH 13/14] cyan-> dark slate blue; conditional coloring of text on bars to -> ghostwhite --- doc/python/horizontal-bar-charts.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/python/horizontal-bar-charts.md b/doc/python/horizontal-bar-charts.md index 04c57fd2104..8ad1343b57d 100644 --- a/doc/python/horizontal-bar-charts.md +++ b/doc/python/horizontal-bar-charts.md @@ -118,7 +118,7 @@ import plotly.graph_objects as go top_labels = ['Strongly
agree', 'Agree', 'Neutral', 'Disagree', 'Strongly
disagree'] -colors = ['DarkBlue', 'MediumBlue', 'cyan', 'mediumpurple', 'thistle'] +colors = ['DarkBlue', 'MediumBlue', 'DarkSlateBlue', 'mediumpurple', 'thistle'] x_data = [[21, 30, 21, 16, 12], [24, 31, 19, 15, 11], [27, 26, 23, 11, 13], @@ -197,7 +197,7 @@ for yd, xd in zip(y_data, x_data): x=space + (xd[i]/2), y=yd, text=str(xd[i]) + '%', font=dict(family='Arial', size=14, - color=f"{'white'*(i<2)}{'black'*(i>=2)}"), + color='ghostwhite'), showarrow=False)) # labeling the Likert scale if yd == y_data[-1]: From 81a6e9c6d1037b778f608406042b896e805731bb Mon Sep 17 00:00:00 2001 From: Rob Letzler <22990670+rl-utility-man@users.noreply.github.com> Date: Mon, 9 Jun 2025 21:05:27 -0400 Subject: [PATCH 14/14] adding introductory text. --- doc/python/horizontal-bar-charts.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/python/horizontal-bar-charts.md b/doc/python/horizontal-bar-charts.md index 8ad1343b57d..0d1b08fd248 100644 --- a/doc/python/horizontal-bar-charts.md +++ b/doc/python/horizontal-bar-charts.md @@ -112,6 +112,8 @@ fig.show() ### Color Palette for Bar Chart +This bar chart uses a sequential palette to show gradations of responses. Additional color options for sequential palettes are available at [The Urban Institute](https://urbaninstitute.github.io/graphics-styleguide/#color) and [Colorbrewer](https://colorbrewer2.org/#type=sequential) + ```python import plotly.graph_objects as go