Skip to content

Commit 4926e0a

Browse files
authored
Merge branch 'doc-prod' into patch-14
2 parents 81a6e9c + 4f977c2 commit 4926e0a

File tree

5 files changed

+58
-6
lines changed

5 files changed

+58
-6
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: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,49 @@ fig.add_trace(go.Bar(
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

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)