Skip to content

Commit b12a4e2

Browse files
replace rgb codes with CSS colors including plotly recommended colors
1 parent 0026a09 commit b12a4e2

File tree

1 file changed

+24
-26
lines changed

1 file changed

+24
-26
lines changed

doc/python/horizontal-bar-charts.md

Lines changed: 24 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

@@ -118,10 +118,8 @@ import plotly.graph_objects as go
118118
top_labels = ['Strongly<br>agree', 'Agree', 'Neutral', 'Disagree',
119119
'Strongly<br>disagree']
120120

121-
colors = ['rgba(38, 24, 74, 0.8)', 'rgba(71, 58, 131, 0.8)',
122-
'rgba(122, 120, 168, 0.8)', 'rgba(164, 163, 204, 0.85)',
123-
'rgba(190, 192, 213, 1)']
124-
121+
colors = ['DarkBlue', 'MediumBlue', 'cyan', 'mediumpurple', 'thistle']
122+
#, 'silver'
125123
x_data = [[21, 30, 21, 16, 12],
126124
[24, 31, 19, 15, 11],
127125
[27, 26, 23, 11, 13],
@@ -142,7 +140,7 @@ for i in range(0, len(x_data[0])):
142140
orientation='h',
143141
marker=dict(
144142
color=colors[i],
145-
line=dict(color='rgb(248, 248, 249)', width=1)
143+
line=dict(color='ghostwhite', width=1)
146144
)
147145
))
148146

@@ -161,8 +159,8 @@ fig.update_layout(
161159
zeroline=False,
162160
),
163161
barmode='stack',
164-
paper_bgcolor='rgb(248, 248, 255)',
165-
plot_bgcolor='rgb(248, 248, 255)',
162+
paper_bgcolor='lavenderblush',
163+
plot_bgcolor='lavenderblush',
166164
margin=dict(l=120, r=10, t=140, b=80),
167165
showlegend=False,
168166
)
@@ -176,22 +174,22 @@ for yd, xd in zip(y_data, x_data):
176174
xanchor='right',
177175
text=str(yd),
178176
font=dict(family='Arial', size=14,
179-
color='rgb(67, 67, 67)'),
177+
color='dimgray'),
180178
showarrow=False, align='right'))
181179
# labeling the first percentage of each bar (x_axis)
182180
annotations.append(dict(xref='x', yref='y',
183181
x=xd[0] / 2, y=yd,
184182
text=str(xd[0]) + '%',
185183
font=dict(family='Arial', size=14,
186-
color='rgb(248, 248, 255)'),
184+
color='white'),
187185
showarrow=False))
188186
# labeling the first Likert scale (on the top)
189187
if yd == y_data[-1]:
190188
annotations.append(dict(xref='x', yref='paper',
191189
x=xd[0] / 2, y=1.1,
192190
text=top_labels[0],
193191
font=dict(family='Arial', size=14,
194-
color='rgb(67, 67, 67)'),
192+
color='dimgray'),
195193
showarrow=False))
196194
space = xd[0]
197195
for i in range(1, len(xd)):
@@ -200,15 +198,15 @@ for yd, xd in zip(y_data, x_data):
200198
x=space + (xd[i]/2), y=yd,
201199
text=str(xd[i]) + '%',
202200
font=dict(family='Arial', size=14,
203-
color='rgb(248, 248, 255)'),
201+
color=f"{'white'*(i<2)}{'black'*(i>=2)}"),
204202
showarrow=False))
205203
# labeling the Likert scale
206204
if yd == y_data[-1]:
207205
annotations.append(dict(xref='x', yref='paper',
208206
x=space + (xd[i]/2), y=1.1,
209207
text=top_labels[i],
210208
font=dict(family='Arial', size=14,
211-
color='rgb(67, 67, 67)'),
209+
color='dimgray'),
212210
showarrow=False))
213211
space += xd[i]
214212

@@ -314,9 +312,9 @@ fig.add_trace(go.Bar(
314312
x=y_saving,
315313
y=x,
316314
marker=dict(
317-
color='rgba(50, 171, 96, 0.6)',
315+
color='mediumseagreen',
318316
line=dict(
319-
color='rgba(50, 171, 96, 1.0)',
317+
color='seagreen',
320318
width=1),
321319
),
322320
name='Household savings, percentage of household disposable income',
@@ -326,7 +324,7 @@ fig.add_trace(go.Bar(
326324
fig.add_trace(go.Scatter(
327325
x=y_net_worth, y=x,
328326
mode='lines+markers',
329-
line_color='rgb(128, 0, 128)',
327+
line_color='purple',
330328
name='Household net worth, Million USD/capita',
331329
), 1, 2)
332330

@@ -342,7 +340,7 @@ fig.update_layout(
342340
showgrid=False,
343341
showline=True,
344342
showticklabels=False,
345-
linecolor='rgba(102, 102, 102, 0.8)',
343+
linecolor='gray',
346344
linewidth=2,
347345
domain=[0, 0.85],
348346
),
@@ -364,8 +362,8 @@ fig.update_layout(
364362
),
365363
legend=dict(x=0.029, y=1.038, font_size=10),
366364
margin=dict(l=100, r=20, t=70, b=70),
367-
paper_bgcolor='rgb(248, 248, 255)',
368-
plot_bgcolor='rgb(248, 248, 255)',
365+
paper_bgcolor='lavenderblush',
366+
plot_bgcolor='lavenderblush',
369367
)
370368

371369
annotations = []
@@ -380,14 +378,14 @@ for ydn, yd, xd in zip(y_nw, y_s, x):
380378
y=xd, x=ydn - 20000,
381379
text='{:,}'.format(ydn) + 'M',
382380
font=dict(family='Arial', size=12,
383-
color='rgb(128, 0, 128)'),
381+
color='purple'),
384382
showarrow=False))
385383
# labeling the bar net worth
386384
annotations.append(dict(xref='x1', yref='y1',
387385
y=xd, x=yd + 3,
388386
text=str(yd) + '%',
389-
font=dict(family='Arial', size=12,
390-
color='rgb(50, 171, 96)'),
387+
font=dict(family='Arial', size=16,
388+
color='mediumseagreen'),
391389
showarrow=False))
392390
# Source
393391
annotations.append(dict(xref='paper', yref='paper',
@@ -396,7 +394,7 @@ annotations.append(dict(xref='paper', yref='paper',
396394
'(2015), Household savings (indicator), ' +
397395
'Household net worth (indicator). doi: ' +
398396
'10.1787/cfc6f499-en (Accessed on 05 June 2015)',
399-
font=dict(family='Arial', size=10, color='rgb(150,150,150)'),
397+
font=dict(family='Arial', size=10, color='gray'),
400398
showarrow=False))
401399

402400
fig.update_layout(annotations=annotations)

0 commit comments

Comments
 (0)