Skip to content

Commit d293a45

Browse files
authored
Merge pull request #5175 from rl-utility-man/patch-14
replace rgb codes with CSS colors including plotly recommended colors
2 parents 4f977c2 + 4926e0a commit d293a45

File tree

1 file changed

+25
-26
lines changed

1 file changed

+25
-26
lines changed

doc/python/horizontal-bar-charts.md

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ fig.add_trace(go.Bar(
9191
name='SF Zoo',
9292
orientation='h',
9393
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)
9696
)
9797
))
9898
fig.add_trace(go.Bar(
@@ -101,8 +101,8 @@ fig.add_trace(go.Bar(
101101
name='LA Zoo',
102102
orientation='h',
103103
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)
106106
)
107107
))
108108

@@ -155,16 +155,15 @@ fig.show()
155155

156156
### Color Palette for Bar Chart
157157

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+
158160
```python
159161
import plotly.graph_objects as go
160162

161163
top_labels = ['Strongly<br>agree', 'Agree', 'Neutral', 'Disagree',
162164
'Strongly<br>disagree']
163165

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']
168167
x_data = [[21, 30, 21, 16, 12],
169168
[24, 31, 19, 15, 11],
170169
[27, 26, 23, 11, 13],
@@ -185,7 +184,7 @@ for i in range(0, len(x_data[0])):
185184
orientation='h',
186185
marker=dict(
187186
color=colors[i],
188-
line=dict(color='rgb(248, 248, 249)', width=1)
187+
line=dict(color='ghostwhite', width=1)
189188
)
190189
))
191190

@@ -204,8 +203,8 @@ fig.update_layout(
204203
zeroline=False,
205204
),
206205
barmode='stack',
207-
paper_bgcolor='rgb(248, 248, 255)',
208-
plot_bgcolor='rgb(248, 248, 255)',
206+
paper_bgcolor='lavenderblush',
207+
plot_bgcolor='lavenderblush',
209208
margin=dict(l=120, r=10, t=140, b=80),
210209
showlegend=False,
211210
)
@@ -219,22 +218,22 @@ for yd, xd in zip(y_data, x_data):
219218
xanchor='right',
220219
text=str(yd),
221220
font=dict(family='Arial', size=14,
222-
color='rgb(67, 67, 67)'),
221+
color='dimgray'),
223222
showarrow=False, align='right'))
224223
# labeling the first percentage of each bar (x_axis)
225224
annotations.append(dict(xref='x', yref='y',
226225
x=xd[0] / 2, y=yd,
227226
text=str(xd[0]) + '%',
228227
font=dict(family='Arial', size=14,
229-
color='rgb(248, 248, 255)'),
228+
color='white'),
230229
showarrow=False))
231230
# labeling the first Likert scale (on the top)
232231
if yd == y_data[-1]:
233232
annotations.append(dict(xref='x', yref='paper',
234233
x=xd[0] / 2, y=1.1,
235234
text=top_labels[0],
236235
font=dict(family='Arial', size=14,
237-
color='rgb(67, 67, 67)'),
236+
color='dimgray'),
238237
showarrow=False))
239238
space = xd[0]
240239
for i in range(1, len(xd)):
@@ -243,15 +242,15 @@ for yd, xd in zip(y_data, x_data):
243242
x=space + (xd[i]/2), y=yd,
244243
text=str(xd[i]) + '%',
245244
font=dict(family='Arial', size=14,
246-
color='rgb(248, 248, 255)'),
245+
color='ghostwhite'),
247246
showarrow=False))
248247
# labeling the Likert scale
249248
if yd == y_data[-1]:
250249
annotations.append(dict(xref='x', yref='paper',
251250
x=space + (xd[i]/2), y=1.1,
252251
text=top_labels[i],
253252
font=dict(family='Arial', size=14,
254-
color='rgb(67, 67, 67)'),
253+
color='dimgray'),
255254
showarrow=False))
256255
space += xd[i]
257256

@@ -357,9 +356,9 @@ fig.add_trace(go.Bar(
357356
x=y_saving,
358357
y=x,
359358
marker=dict(
360-
color='rgba(50, 171, 96, 0.6)',
359+
color='mediumseagreen',
361360
line=dict(
362-
color='rgba(50, 171, 96, 1.0)',
361+
color='seagreen',
363362
width=1),
364363
),
365364
name='Household savings, percentage of household disposable income',
@@ -369,7 +368,7 @@ fig.add_trace(go.Bar(
369368
fig.add_trace(go.Scatter(
370369
x=y_net_worth, y=x,
371370
mode='lines+markers',
372-
line_color='rgb(128, 0, 128)',
371+
line_color='purple',
373372
name='Household net worth, Million USD/capita',
374373
), 1, 2)
375374

@@ -385,7 +384,7 @@ fig.update_layout(
385384
showgrid=False,
386385
showline=True,
387386
showticklabels=False,
388-
linecolor='rgba(102, 102, 102, 0.8)',
387+
linecolor='gray',
389388
linewidth=2,
390389
domain=[0, 0.85],
391390
),
@@ -407,8 +406,8 @@ fig.update_layout(
407406
),
408407
legend=dict(x=0.029, y=1.038, font_size=10),
409408
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',
412411
)
413412

414413
annotations = []
@@ -423,14 +422,14 @@ for ydn, yd, xd in zip(y_nw, y_s, x):
423422
y=xd, x=ydn - 20000,
424423
text='{:,}'.format(ydn) + 'M',
425424
font=dict(family='Arial', size=12,
426-
color='rgb(128, 0, 128)'),
425+
color='purple'),
427426
showarrow=False))
428427
# labeling the bar net worth
429428
annotations.append(dict(xref='x1', yref='y1',
430429
y=xd, x=yd + 3,
431430
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'),
434433
showarrow=False))
435434
# Source
436435
annotations.append(dict(xref='paper', yref='paper',
@@ -439,7 +438,7 @@ annotations.append(dict(xref='paper', yref='paper',
439438
'(2015), Household savings (indicator), ' +
440439
'Household net worth (indicator). doi: ' +
441440
'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'),
443442
showarrow=False))
444443

445444
fig.update_layout(annotations=annotations)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy