Skip to content

add example showing how to customize figure subplot titles #2221

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 1 commit into from
Feb 24, 2020
Merged
Changes from all commits
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
26 changes: 20 additions & 6 deletions doc/python/facet-plots.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ jupyter:
text_representation:
extension: .md
format_name: markdown
format_version: "1.1"
jupytext_version: 1.1.1
format_version: '1.2'
jupytext_version: 1.3.4
kernelspec:
display_name: Python 3
language: python
Expand All @@ -20,7 +20,7 @@ jupyter:
name: python
nbconvert_exporter: python
pygments_lexer: ipython3
version: 3.6.8
version: 3.7.0
plotly:
description: How to make Facet and Trellis Plots in Python with Plotly.
display_as: statistical
Expand All @@ -31,8 +31,8 @@ jupyter:
page_type: u-guide
permalink: python/facet-plots/
redirect_from:
- python/trellis-plots/
- python/facet-trellis/
- python/trellis-plots/
- python/facet-trellis/
Copy link
Contributor

Choose a reason for hiding this comment

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

did you change this yourself or was it Jupyter? From a quick grep I think we have the two syntaxes in the doc directory, so this should be fine, but just checking.

Copy link
Author

Choose a reason for hiding this comment

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

It was Jupyter, not me that edited the front matter.

Copy link
Contributor

Choose a reason for hiding this comment

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

ok, 💃!

thumbnail: thumbnail/facet-trellis-thumbnail.jpg
---

Expand Down Expand Up @@ -81,7 +81,7 @@ fig = px.histogram(df, x="total_bill", y="tip", color="sex", facet_row="time", f
fig.show()
```

### Facets with independent axes
### 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 when you use `facet_row` only, by disabling `matches` on the Y axes, or when using `facet_col` only, by disabling `matches` on the X axes. It is not recommended to use this approach when using `facet_row` and `facet_col` together, as in this case it becomes very hard to understand the labelling of axes and grid lines.

Expand All @@ -101,6 +101,20 @@ fig.update_xaxes(matches=None)
fig.show()
```

### Customize Subplot Figure Titles

Since subplot figure titles are [annotations](https://plot.ly/python/text-and-annotations/#simple-annotation), you can use the `for_each_annotation` function to customize them.

In the following example, we pass a lambda function to `for_each_annotation` in order to change the figure subplot titles from `smoker=No` and `smoker=Yes` to just `No` and `Yes`.

```python
import plotly.express as px

fig = px.scatter(px.data.tips(), x="total_bill", y="tip", facet_col="smoker")
fig.for_each_annotation(lambda a: a.update(text=a.text.split("=")[-1]))
fig.show()
```

```python

```