Skip to content

Update facet-plots.md #2235

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 3 commits into from
Mar 4, 2020
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
17 changes: 17 additions & 0 deletions doc/python/facet-plots.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,20 @@ fig.show()
```python

```

### Zooming subplots to the same range
Copy link
Contributor

Choose a reason for hiding this comment

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

matches does actually more than synchronizing zoom, you also have synchronized panning for example. How about a more general title like "Synchronizing axes in subplots with matches"? Also what do you think of mentioning pan and zoom in the text below (compared to just zoom at the moment?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure! I will edit the title and mention the pan.


Using `facet_col` from `plotly.express` let zoom each facet to the same range impliciltly. However, if the subplots are created with `make_subplots`, the axis needs to be updated with `matches` parameter to zoom all the subplots accordingly. Zoom in one trace below, to see the other subplots zoomed to the same x-axis range:

```python
import plotly.graph_objects as go
from plotly.subplots import make_subplots
import numpy as np
N = 20
x = np.linspace(0, 1, N)
fig = make_subplots(1, 3)
for i in range(1, 4):
fig.add_trace(go.Scatter(x=x, y=np.random.random(N)), 1, i)
fig.update_xaxes(matches='x')
fig.show()
```