@@ -91,8 +91,8 @@ fig.add_trace(go.Bar(
91
91
name = ' SF Zoo' ,
92
92
orientation = ' h' ,
93
93
marker = dict (
94
- color = ' rgba(246, 78, 139, 0.6) ' ,
95
- line = dict (color = ' rgba(246, 78, 139, 1.0) ' , width = 3 )
94
+ color = ' hotpink ' ,
95
+ line = dict (color = ' deeppink ' , width = 3 )
96
96
)
97
97
))
98
98
fig.add_trace(go.Bar(
@@ -101,8 +101,8 @@ fig.add_trace(go.Bar(
101
101
name = ' LA Zoo' ,
102
102
orientation = ' h' ,
103
103
marker = dict (
104
- color = ' rgba(58, 71, 80, 0.6) ' ,
105
- line = dict (color = ' rgba(58, 71, 80, 1.0) ' , width = 3 )
104
+ color = ' dimgray ' ,
105
+ line = dict (color = ' black ' , width = 3 )
106
106
)
107
107
))
108
108
@@ -155,16 +155,15 @@ fig.show()
155
155
156
156
### Color Palette for Bar Chart
157
157
158
+ 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 )
159
+
158
160
``` python
159
161
import plotly.graph_objects as go
160
162
161
163
top_labels = [' Strongly<br>agree' , ' Agree' , ' Neutral' , ' Disagree' ,
162
164
' Strongly<br>disagree' ]
163
165
164
- colors = [' rgba(38, 24, 74, 0.8)' , ' rgba(71, 58, 131, 0.8)' ,
165
- ' rgba(122, 120, 168, 0.8)' , ' rgba(164, 163, 204, 0.85)' ,
166
- ' rgba(190, 192, 213, 1)' ]
167
-
166
+ colors = [' DarkBlue' , ' MediumBlue' , ' DarkSlateBlue' , ' mediumpurple' , ' thistle' ]
168
167
x_data = [[21 , 30 , 21 , 16 , 12 ],
169
168
[24 , 31 , 19 , 15 , 11 ],
170
169
[27 , 26 , 23 , 11 , 13 ],
@@ -185,7 +184,7 @@ for i in range(0, len(x_data[0])):
185
184
orientation = ' h' ,
186
185
marker = dict (
187
186
color = colors[i],
188
- line = dict (color = ' rgb(248, 248, 249) ' , width = 1 )
187
+ line = dict (color = ' ghostwhite ' , width = 1 )
189
188
)
190
189
))
191
190
@@ -204,8 +203,8 @@ fig.update_layout(
204
203
zeroline = False ,
205
204
),
206
205
barmode = ' stack' ,
207
- paper_bgcolor = ' rgb(248, 248, 255) ' ,
208
- plot_bgcolor = ' rgb(248, 248, 255) ' ,
206
+ paper_bgcolor = ' lavenderblush ' ,
207
+ plot_bgcolor = ' lavenderblush ' ,
209
208
margin = dict (l = 120 , r = 10 , t = 140 , b = 80 ),
210
209
showlegend = False ,
211
210
)
@@ -219,22 +218,22 @@ for yd, xd in zip(y_data, x_data):
219
218
xanchor = ' right' ,
220
219
text = str (yd),
221
220
font = dict (family = ' Arial' , size = 14 ,
222
- color = ' rgb(67, 67, 67) ' ),
221
+ color = ' dimgray ' ),
223
222
showarrow = False , align = ' right' ))
224
223
# labeling the first percentage of each bar (x_axis)
225
224
annotations.append(dict (xref = ' x' , yref = ' y' ,
226
225
x = xd[0 ] / 2 , y = yd,
227
226
text = str (xd[0 ]) + ' %' ,
228
227
font = dict (family = ' Arial' , size = 14 ,
229
- color = ' rgb(248, 248, 255) ' ),
228
+ color = ' white ' ),
230
229
showarrow = False ))
231
230
# labeling the first Likert scale (on the top)
232
231
if yd == y_data[- 1 ]:
233
232
annotations.append(dict (xref = ' x' , yref = ' paper' ,
234
233
x = xd[0 ] / 2 , y = 1.1 ,
235
234
text = top_labels[0 ],
236
235
font = dict (family = ' Arial' , size = 14 ,
237
- color = ' rgb(67, 67, 67) ' ),
236
+ color = ' dimgray ' ),
238
237
showarrow = False ))
239
238
space = xd[0 ]
240
239
for i in range (1 , len (xd)):
@@ -243,15 +242,15 @@ for yd, xd in zip(y_data, x_data):
243
242
x = space + (xd[i]/ 2 ), y = yd,
244
243
text = str (xd[i]) + ' %' ,
245
244
font = dict (family = ' Arial' , size = 14 ,
246
- color = ' rgb(248, 248, 255) ' ),
245
+ color = ' ghostwhite ' ),
247
246
showarrow = False ))
248
247
# labeling the Likert scale
249
248
if yd == y_data[- 1 ]:
250
249
annotations.append(dict (xref = ' x' , yref = ' paper' ,
251
250
x = space + (xd[i]/ 2 ), y = 1.1 ,
252
251
text = top_labels[i],
253
252
font = dict (family = ' Arial' , size = 14 ,
254
- color = ' rgb(67, 67, 67) ' ),
253
+ color = ' dimgray ' ),
255
254
showarrow = False ))
256
255
space += xd[i]
257
256
@@ -357,9 +356,9 @@ fig.add_trace(go.Bar(
357
356
x = y_saving,
358
357
y = x,
359
358
marker = dict (
360
- color = ' rgba(50, 171, 96, 0.6) ' ,
359
+ color = ' mediumseagreen ' ,
361
360
line = dict (
362
- color = ' rgba(50, 171, 96, 1.0) ' ,
361
+ color = ' seagreen ' ,
363
362
width = 1 ),
364
363
),
365
364
name = ' Household savings, percentage of household disposable income' ,
@@ -369,7 +368,7 @@ fig.add_trace(go.Bar(
369
368
fig.add_trace(go.Scatter(
370
369
x = y_net_worth, y = x,
371
370
mode = ' lines+markers' ,
372
- line_color = ' rgb(128, 0, 128) ' ,
371
+ line_color = ' purple ' ,
373
372
name = ' Household net worth, Million USD/capita' ,
374
373
), 1 , 2 )
375
374
@@ -385,7 +384,7 @@ fig.update_layout(
385
384
showgrid = False ,
386
385
showline = True ,
387
386
showticklabels = False ,
388
- linecolor = ' rgba(102, 102, 102, 0.8) ' ,
387
+ linecolor = ' gray ' ,
389
388
linewidth = 2 ,
390
389
domain = [0 , 0.85 ],
391
390
),
@@ -407,8 +406,8 @@ fig.update_layout(
407
406
),
408
407
legend = dict (x = 0.029 , y = 1.038 , font_size = 10 ),
409
408
margin = dict (l = 100 , r = 20 , t = 70 , b = 70 ),
410
- paper_bgcolor = ' rgb(248, 248, 255) ' ,
411
- plot_bgcolor = ' rgb(248, 248, 255) ' ,
409
+ paper_bgcolor = ' lavenderblush ' ,
410
+ plot_bgcolor = ' lavenderblush ' ,
412
411
)
413
412
414
413
annotations = []
@@ -423,14 +422,14 @@ for ydn, yd, xd in zip(y_nw, y_s, x):
423
422
y = xd, x = ydn - 20000 ,
424
423
text = ' {:, } ' .format(ydn) + ' M' ,
425
424
font = dict (family = ' Arial' , size = 12 ,
426
- color = ' rgb(128, 0, 128) ' ),
425
+ color = ' purple ' ),
427
426
showarrow = False ))
428
427
# labeling the bar net worth
429
428
annotations.append(dict (xref = ' x1' , yref = ' y1' ,
430
429
y = xd, x = yd + 3 ,
431
430
text = str (yd) + ' %' ,
432
- font = dict (family = ' Arial' , size = 12 ,
433
- color = ' rgb(50, 171, 96) ' ),
431
+ font = dict (family = ' Arial' , size = 16 ,
432
+ color = ' mediumseagreen ' ),
434
433
showarrow = False ))
435
434
# Source
436
435
annotations.append(dict (xref = ' paper' , yref = ' paper' ,
@@ -439,7 +438,7 @@ annotations.append(dict(xref='paper', yref='paper',
439
438
' (2015), Household savings (indicator), ' +
440
439
' Household net worth (indicator). doi: ' +
441
440
' 10.1787/cfc6f499-en (Accessed on 05 June 2015)' ,
442
- font = dict (family = ' Arial' , size = 10 , color = ' rgb(150,150,150) ' ),
441
+ font = dict (family = ' Arial' , size = 10 , color = ' gray ' ),
443
442
showarrow = False ))
444
443
445
444
fig.update_layout(annotations = annotations)
0 commit comments