Skip to content

Commit 70b7f49

Browse files
improved the comments.
1 parent 40cd4c8 commit 70b7f49

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

doc/python/horizontal-bar-charts.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -218,15 +218,14 @@ fig.show()
218218
```
219219
### Diverging Bar (or Butterfly) Chart with Neutral Column
220220

221-
Diverging bar charts offer two imperfect options for responses that are neither positive nor negative: omit them, leaving them implicit when the categories add to 100%, as we did above or put them in a separate column, as we do in this example. Jonathan Schwabish discusses this on page 92-97 of _Better Data Visualizations_.
221+
Diverging bar charts offer two imperfect options for responses that are neither positive nor negative: put them in a separate column, as in this example or omit them as in the example above. That leaves the unreported neutral value implicit when the categories add to 100%, Jonathan Schwabish discusses this on page 92-97 of _Better Data Visualizations_.
222222

223223
```
224224
import pandas as pd
225225
import plotly.graph_objects as go
226226
227227
228228
df = pd.read_csv('https://github.com/plotly/datasets/refs/heads/master/gss_2002_5_pt_likert.csv')
229-
#data source details are in this CSV file
230229
df.rename(columns={'Unnamed: 0':"Category"}, inplace=True)
231230
232231
@@ -235,7 +234,7 @@ for v in ["Disagree","Strongly Disagree"]:
235234
df[v]=df[v]*-1
236235
237236
fig = go.Figure()
238-
# this color palette conveys meaning: blues for negative, reds for positive, gray for Neither Agree nor Disagree
237+
# this color palette conveys meaning: blues for agreement, reds and oranges for disagreement, gray for Neither Agree nor Disagree
239238
color_by_category={
240239
"Strongly Agree":'darkblue',
241240
"Agree":'lightblue',
@@ -285,25 +284,27 @@ max_width_signed = abs(max_left)+max_right
285284
max_width_neither = max(df["Neither Agree nor Disagree"])
286285
287286
fig.update_layout(
288-
289287
title="Reactions to statements from the 2002 General Social Survey:",
290288
plot_bgcolor="white",
291289
barmode='relative', # Allows bars to diverge from the center
292290
)
291+
293292
fig.update_xaxes(
294293
zeroline=True, #the zero line distinguishes between positive and negative segments
295294
zerolinecolor="black",
296295
#starting here, we set domain and range to create a shared x-axis scale
297296
# multiply by .98 to add space between the two columns
298297
range=[max_left, max_right],
299298
domain=[0, 0.98*(max_width_signed/(max_width_signed+max_width_neither))]
300-
)
299+
)
300+
301301
fig.update_layout(
302302
xaxis2=dict(
303303
range=[0, max_width_neither],
304304
domain=[(1-.98*(1-max_width_signed/(max_width_signed+max_width_neither))), 1.0],
305305
)
306306
)
307+
307308
fig.update_legends(
308309
orientation="h", # a horizontal legend matches the horizontal bars
309310
yref="container",

0 commit comments

Comments
 (0)