Skip to content

Commit 0f9141b

Browse files
authored
Merge pull request #5235 from plotly/merge-doc-prod-changes-to-main
Merge recent doc prod changes to main
2 parents fbb65c8 + a09b2de commit 0f9141b

File tree

5 files changed

+83
-32
lines changed

5 files changed

+83
-32
lines changed

doc/python/dropdowns.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -365,27 +365,27 @@ fig.add_trace(
365365
go.Scatter(x=list(df.Date),
366366
y=list(df.High),
367367
name="High",
368-
line=dict(color="#33CFA5")))
368+
line=dict(color="DarkBlue")))
369369

370370
fig.add_trace(
371371
go.Scatter(x=list(df.Date),
372372
y=[df.High.mean()] * len(df.index),
373373
name="High Average",
374374
visible=False,
375-
line=dict(color="#33CFA5", dash="dash")))
375+
line=dict(color="DarkBlue", dash="dash")))
376376

377377
fig.add_trace(
378378
go.Scatter(x=list(df.Date),
379379
y=list(df.Low),
380380
name="Low",
381-
line=dict(color="#F06A6A")))
381+
line=dict(color="Crimson")))
382382

383383
fig.add_trace(
384384
go.Scatter(x=list(df.Date),
385385
y=[df.Low.mean()] * len(df.index),
386386
name="Low Average",
387387
visible=False,
388-
line=dict(color="#F06A6A", dash="dash")))
388+
line=dict(color="Crimson", dash="dash")))
389389

390390
# Add Annotations and Buttons
391391
high_annotations = [dict(x="2016-03-01",

doc/python/facet-plots.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ fig.show()
5454

5555
### Bar Chart Row Facets
5656

57+
There is a more presentation-ready horizontal, faceted bar chart in the [horizontal bar documentation](/python/horizontal-bar-charts/#Small-multiple-horizontal-bar-charts-show-each-component's-size-more-clearly-than-a-stacked-bar)
58+
5759
```python
5860
import plotly.express as px
5961
df = px.data.tips()

doc/python/graph-objects.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ Note that the figures produced by Plotly Express **in a single function-call** a
6868

6969
The figures produced by Plotly Express can always be built from the ground up using graph objects, but this approach typically takes **5-100 lines of code rather than 1**.
7070

71-
Here is a simple example of how to produce the same figure object from the same data, once with Plotly Express and once without. The data in this example is in "long form" but [Plotly Express also accepts data in "wide form"](/python/wide-form/) and the line-count savings from Plotly Express over graph objects are comparable. More complex figures such as [sunbursts](/python/sunburst-charts/), [parallel coordinates](/python/parallel-coordinates-plot/), [facet plots](/python/facet-plots/) or [animations](/python/animations/) require many more lines of figure-specific graph objects code, whereas switching from one representation to another with Plotly Express usually involves changing just a few characters.
71+
Here is a simple example of how to produce the same figure object from the same data, once with Plotly Express and once without. Note that [Plotly Express functions](/python-api-reference/plotly.express.html) like [`px.bar()`](/python/bar-charts/) can accept a DataFrame as their first argument with column names passed to the `x` and `y` arguments, while [Graph Objects functions](/python-api-reference/plotly.graph_objects.html) like [`go.Bar()`](/python/bar-charts/#basic-bar-charts-with-plotlygraphobjects) require the data values to be passed directly to the `x` and `y` arguments as a tuple, list, NumPy array, or Pandas Series.
72+
73+
The data in this example is in "long form" but [Plotly Express also accepts data in "wide form"](/python/wide-form/) and the line-count savings from Plotly Express over graph objects are comparable. More complex figures such as [sunbursts](/python/sunburst-charts/), [parallel coordinates](/python/parallel-coordinates-plot/), [facet plots](/python/facet-plots/) or [animations](/python/animations/) require many more lines of figure-specific graph objects code, whereas switching from one representation to another with Plotly Express usually involves changing just a few characters.
7274

7375
```python
7476
import pandas as pd

doc/python/horizontal-bar-charts.md

Lines changed: 68 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,27 +101,69 @@ 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

109109
fig.update_layout(barmode='stack')
110+
fig.show()
111+
```
112+
### Small multiple horizontal bar charts show each component's size more clearly than a stacked bar
113+
114+
Bar charts with multiple components pose a fundamental trade off between presenting the total clearly and presenting the component values clearly. This small multiples approach shows the component magnitudes clearly at the cost of slightly obscuring the totals. A stacked bar does the opposite. Small multiple bar charts often work better in a horizontal orientation; and are easy to create with the px.bar orientation and facet_col parameters.
115+
```python
116+
import pandas as pd
117+
import plotly.express as px
118+
119+
data = {
120+
"Quarter": ["Q1", "Q2", "Q3", "Q4"] * 3,
121+
"Region": ["North", "North", "North", "North", "South", "South", "South", "South", "West", "West", "West", "West"],
122+
"Outcome": [150, 200, 250, 300, 120, 180, 240, 310, 100, 150, 220, 280]
123+
}
124+
df = pd.DataFrame(data)
125+
126+
127+
fig = px.bar(
128+
df,
129+
x="Outcome",
130+
y="Region",
131+
orientation="h",
132+
facet_col="Quarter",
133+
title="Number of Patients Served by Region and Quarter",
134+
labels={"Outcome": "Patients Served", "Region": "Region"}
135+
)
136+
137+
## the section below is optional clean up to make this presentation ready
138+
139+
fig.update_layout(
140+
height=400, #the Plotly default makes the bars awkwardly large; setting a height improves the display
141+
showlegend=False, # the legend does not add anything
142+
)
143+
144+
# remove the default "facet_variable =" text from the title of each facet graph
145+
fig.for_each_annotation(lambda a: a.update(text=a.text.split("=")[-1]))
146+
147+
# Remove duplicate axis labels
148+
fig.for_each_yaxis(lambda axis: axis.update(title=None))
149+
fig.for_each_xaxis(lambda axis: axis.update(title=None))
150+
# add the one valuable axis label back in
151+
fig.update_xaxes(title="Count", row=1, col=1)
152+
110153
fig.show()
111154
```
112155

113156
### Color Palette for Bar Chart
114157

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+
115160
```python
116161
import plotly.graph_objects as go
117162

118163
top_labels = ['Strongly<br>agree', 'Agree', 'Neutral', 'Disagree',
119164
'Strongly<br>disagree']
120165

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-
166+
colors = ['DarkBlue', 'MediumBlue', 'DarkSlateBlue', 'mediumpurple', 'thistle']
125167
x_data = [[21, 30, 21, 16, 12],
126168
[24, 31, 19, 15, 11],
127169
[27, 26, 23, 11, 13],
@@ -142,7 +184,7 @@ for i in range(0, len(x_data[0])):
142184
orientation='h',
143185
marker=dict(
144186
color=colors[i],
145-
line=dict(color='rgb(248, 248, 249)', width=1)
187+
line=dict(color='ghostwhite', width=1)
146188
)
147189
))
148190

@@ -161,8 +203,8 @@ fig.update_layout(
161203
zeroline=False,
162204
),
163205
barmode='stack',
164-
paper_bgcolor='rgb(248, 248, 255)',
165-
plot_bgcolor='rgb(248, 248, 255)',
206+
paper_bgcolor='lavenderblush',
207+
plot_bgcolor='lavenderblush',
166208
margin=dict(l=120, r=10, t=140, b=80),
167209
showlegend=False,
168210
)
@@ -176,22 +218,22 @@ for yd, xd in zip(y_data, x_data):
176218
xanchor='right',
177219
text=str(yd),
178220
font=dict(family='Arial', size=14,
179-
color='rgb(67, 67, 67)'),
221+
color='dimgray'),
180222
showarrow=False, align='right'))
181223
# labeling the first percentage of each bar (x_axis)
182224
annotations.append(dict(xref='x', yref='y',
183225
x=xd[0] / 2, y=yd,
184226
text=str(xd[0]) + '%',
185227
font=dict(family='Arial', size=14,
186-
color='rgb(248, 248, 255)'),
228+
color='white'),
187229
showarrow=False))
188230
# labeling the first Likert scale (on the top)
189231
if yd == y_data[-1]:
190232
annotations.append(dict(xref='x', yref='paper',
191233
x=xd[0] / 2, y=1.1,
192234
text=top_labels[0],
193235
font=dict(family='Arial', size=14,
194-
color='rgb(67, 67, 67)'),
236+
color='dimgray'),
195237
showarrow=False))
196238
space = xd[0]
197239
for i in range(1, len(xd)):
@@ -200,15 +242,15 @@ for yd, xd in zip(y_data, x_data):
200242
x=space + (xd[i]/2), y=yd,
201243
text=str(xd[i]) + '%',
202244
font=dict(family='Arial', size=14,
203-
color='rgb(248, 248, 255)'),
245+
color='ghostwhite'),
204246
showarrow=False))
205247
# labeling the Likert scale
206248
if yd == y_data[-1]:
207249
annotations.append(dict(xref='x', yref='paper',
208250
x=space + (xd[i]/2), y=1.1,
209251
text=top_labels[i],
210252
font=dict(family='Arial', size=14,
211-
color='rgb(67, 67, 67)'),
253+
color='dimgray'),
212254
showarrow=False))
213255
space += xd[i]
214256

@@ -313,9 +355,9 @@ fig.add_trace(go.Bar(
313355
x=y_saving,
314356
y=x,
315357
marker=dict(
316-
color='rgba(50, 171, 96, 0.6)',
358+
color='mediumseagreen',
317359
line=dict(
318-
color='rgba(50, 171, 96, 1.0)',
360+
color='seagreen',
319361
width=1),
320362
),
321363
name='Household savings, percentage of household disposable income',
@@ -325,7 +367,7 @@ fig.add_trace(go.Bar(
325367
fig.add_trace(go.Scatter(
326368
x=y_net_worth, y=x,
327369
mode='lines+markers',
328-
line_color='rgb(128, 0, 128)',
370+
line_color='purple',
329371
name='Household net worth, Million USD/capita',
330372
), 1, 2)
331373

@@ -341,7 +383,7 @@ fig.update_layout(
341383
showgrid=False,
342384
showline=True,
343385
showticklabels=False,
344-
linecolor='rgba(102, 102, 102, 0.8)',
386+
linecolor='gray',
345387
linewidth=2,
346388
domain=[0, 0.85],
347389
),
@@ -363,8 +405,8 @@ fig.update_layout(
363405
),
364406
legend=dict(x=0.029, y=1.038, font_size=10),
365407
margin=dict(l=100, r=20, t=70, b=70),
366-
paper_bgcolor='rgb(248, 248, 255)',
367-
plot_bgcolor='rgb(248, 248, 255)',
408+
paper_bgcolor='lavenderblush',
409+
plot_bgcolor='lavenderblush',
368410
)
369411

370412
annotations = []
@@ -379,14 +421,14 @@ for ydn, yd, xd in zip(y_nw, y_s, x):
379421
y=xd, x=ydn - 20000,
380422
text='{:,}'.format(ydn) + 'M',
381423
font=dict(family='Arial', size=12,
382-
color='rgb(128, 0, 128)'),
424+
color='purple'),
383425
showarrow=False))
384426
# labeling the bar net worth
385427
annotations.append(dict(xref='x1', yref='y1',
386428
y=xd, x=yd + 3,
387429
text=str(yd) + '%',
388-
font=dict(family='Arial', size=12,
389-
color='rgb(50, 171, 96)'),
430+
font=dict(family='Arial', size=16,
431+
color='mediumseagreen'),
390432
showarrow=False))
391433
# Source
392434
annotations.append(dict(xref='paper', yref='paper',
@@ -395,7 +437,7 @@ annotations.append(dict(xref='paper', yref='paper',
395437
'(2015), Household savings (indicator), ' +
396438
'Household net worth (indicator). doi: ' +
397439
'10.1787/cfc6f499-en (Accessed on 05 June 2015)',
398-
font=dict(family='Arial', size=10, color='rgb(150,150,150)'),
440+
font=dict(family='Arial', size=10, color='gray'),
399441
showarrow=False))
400442

401443
fig.update_layout(annotations=annotations)

plotly/express/_doc.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,12 @@
612612
def make_docstring(fn, override_dict=None, append_dict=None):
613613
override_dict = {} if override_dict is None else override_dict
614614
append_dict = {} if append_dict is None else append_dict
615-
tw = TextWrapper(width=75, initial_indent=" ", subsequent_indent=" ")
615+
tw = TextWrapper(
616+
width=75,
617+
initial_indent=" ",
618+
subsequent_indent=" ",
619+
break_on_hyphens=False,
620+
)
616621
result = (fn.__doc__ or "") + "\nParameters\n----------\n"
617622
for param in getfullargspec(fn)[0]:
618623
if override_dict.get(param):

0 commit comments

Comments
 (0)