Skip to content

added example about facet_col_wrap, and one example for disabling axis sharing #166

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 12, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
added example about facet_col_wrap, and one example for disabling axi…
…s sharing
  • Loading branch information
emmanuelle authored and nicolaskruchten committed Nov 12, 2019
commit d39828ed699a43cf0a9062e0342000a68b2215d7
31 changes: 30 additions & 1 deletion python/facet-plots.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jupyter:
name: python
nbconvert_exporter: python
pygments_lexer: ipython3
version: 3.6.7
version: 3.7.3
plotly:
description: How to make Facet and Trellis Plots in Python with Plotly.
display_as: statistical
Expand Down Expand Up @@ -58,6 +58,18 @@ fig = px.bar(tips, x="size", y="total_bill", color="sex", facet_row="smoker")
fig.show()
```

### Wrapping Column Facets

When the facet dimension has a large number of unique values, it is possible to wrap columns using the `facet_col_wrap` argument.

```python
import plotly.express as px
df = px.data.gapminder()
fig = px.scatter(df, x='gdpPercap', y='lifeExp', color='continent', size='pop',
facet_col='year', facet_col_wrap=4)
fig.show()
```

### Histogram Facet Grids

```python
Expand All @@ -67,3 +79,20 @@ fig = px.histogram(tips, x="total_bill", y="tip", color="sex", facet_row="time",
category_orders={"day": ["Thur", "Fri", "Sat", "Sun"], "time": ["Lunch", "Dinner"]})
fig.show()
```

### Facets with independent axes

By default, facet axes are linked together: zooming inside one of the facets will also zoom in the other facets. You can disable this behaviour as follows.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here it's actually important to mention that it's dangerous to do what's in this example, because you lose all labelling for plots that aren't on the edges. You should only disable matching for y when using facet_row without facet_col and vice versa!


```python
import plotly.express as px
df = px.data.tips()
fig = px.scatter(df, x="total_bill", y="tip", color='sex',
facet_row="day", facet_col='time')
# No match between subplot axes
fig.update_xaxes(matches=None)
fig.update_yaxes(matches=None)
# Show ticks for each axis since they are now independent
fig.update_xaxes(showticklabels=True)
fig.show()
```