Skip to content

Commit 2140af6

Browse files
moved yaxis title and legned layout to go.Figure()
1 parent be52c35 commit 2140af6

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

doc/python/horizontal-bar-charts.md

+15-13
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,21 @@ for v in ["Disagree","Strongly Disagree"]:
236236
fig = go.Figure(layout=go.Layout(
237237
title="Reactions to statements from the 2002 General Social Survey:",
238238
plot_bgcolor="white",
239-
barmode='relative' # Allows bars to diverge from the center
240-
))
239+
barmode='relative', # Allows bars to diverge from the center
240+
# Put the legend at the bottom center of the figure
241+
legend=dict(
242+
orientation="h", # a horizontal legend matches the horizontal bars
243+
yref="container",
244+
yanchor="bottom",
245+
y=0.02,
246+
xanchor="center",
247+
x=0.5),
248+
# use an unlabeled Y axis, since we're going to list specific questions on the y-axis.
249+
yaxis=dict(
250+
title=""
251+
),
252+
)
253+
)
241254

242255

243256
# this color palette conveys meaning: blues for agreement, reds and oranges for disagreement, gray for Neither Agree nor Disagree
@@ -305,17 +318,6 @@ fig.update_layout(
305318
)
306319
)
307320

308-
fig.update_legends(
309-
orientation="h", # a horizontal legend matches the horizontal bars
310-
yref="container",
311-
yanchor="bottom",
312-
y=0.02,
313-
xanchor="center",
314-
x=0.5
315-
)
316-
317-
fig.update_yaxes(title="")
318-
319321
fig.show()
320322
```
321323

0 commit comments

Comments
 (0)