From 6b0ca58b80e94a487cd00af4ca2d8a4bdef3e43e Mon Sep 17 00:00:00 2001 From: Sylwia Mielnicka Date: Thu, 27 Feb 2020 10:05:12 +0100 Subject: [PATCH 1/2] Update axes.md Added section 'Zooming subplots to the same range' --- doc/python/axes.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/doc/python/axes.md b/doc/python/axes.md index eea8f8daed7..62b4abea553 100644 --- a/doc/python/axes.md +++ b/doc/python/axes.md @@ -741,6 +741,27 @@ fig.update_yaxes(domain=(0.25, 0.75)) fig.show() ``` +### Zooming subplots to the same range + +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() +``` + #### Reference See https://plot.ly/python/reference/#layout-xaxis and https://plot.ly/python/reference/#layout-yaxis for more information and chart attribute options! From 5d44a099508a3e51a0358afc7334a52db77eb0e4 Mon Sep 17 00:00:00 2001 From: Sylwia Mielnicka Date: Tue, 3 Mar 2020 07:16:59 +0100 Subject: [PATCH 2/2] Update axes.md Section `Zooming subplots to the same range` updated accordingly to the analogous section in facet-plots.md --- doc/python/axes.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/python/axes.md b/doc/python/axes.md index 62b4abea553..cdab606651e 100644 --- a/doc/python/axes.md +++ b/doc/python/axes.md @@ -741,9 +741,11 @@ fig.update_yaxes(domain=(0.25, 0.75)) fig.show() ``` -### Zooming subplots to the same range +#### Synchronizing axes in subplots with `matches` -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: +Using `facet_col` from `plotly.express` let [zoom](https://help.plot.ly/zoom-pan-hover-controls/#step-3-zoom-in-and-zoom-out-autoscale-the-plot) and [pan](https://help.plot.ly/zoom-pan-hover-controls/#step-6-pan-along-axes) each facet to the same range implicitly. However, if the subplots are created with `make_subplots`, the axis needs to be updated with `matches` parameter to update all the subplots accordingly. + +Zoom in one trace below, to see the other subplots zoomed to the same x-axis range. To pan all the subplots, click and drag from the center of x-axis to the side: ```python import plotly.graph_objects as go @@ -754,10 +756,8 @@ 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() ```