From 139d42cd82cb65873ec9fcfcc3bcfbd0c831fada Mon Sep 17 00:00:00 2001 From: Liam Connors Date: Thu, 19 Jan 2023 11:38:44 -0500 Subject: [PATCH 1/4] Update multiple-axes.md --- doc/python/multiple-axes.md | 62 +++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/doc/python/multiple-axes.md b/doc/python/multiple-axes.md index 22974ca734f..01eb0f7d367 100644 --- a/doc/python/multiple-axes.md +++ b/doc/python/multiple-axes.md @@ -352,5 +352,67 @@ fig.show() ``` +### Sync Axes Ticks + +*New in 5.13* + + +When you have multiple axes overlayed, each axis by default has its own number of ticks. You can sync the number of ticks on an axis overlayed on another axis by setting `tickmode="sync"`. In this example, we sync the ticks on the `"Total bill amount"` axis with the `"Total number of diners"` axis that it overlays. + +```python +import pandas as pd +import plotly.graph_objects as go +from plotly.data import tips + +df = tips() + +summed_values = df.groupby(by="day", as_index=False).sum(numeric_only=True) +day_order_mapping = {"Thur": 0, "Fri": 1, "Sat": 2, "Sun": 3} +summed_values["order"] = summed_values["day"].apply(lambda day: day_order_mapping[day]) +summed_values = summed_values.sort_values(by="order") + +days_of_week = summed_values["day"].values +total_bills = summed_values["total_bill"].values +number_of_diners = summed_values["size"].values + + +fig = go.Figure( + data=go.Bar( + x=days_of_week, + y=number_of_diners, + name="Total number of diners", + marker=dict(color="paleturquoise"), + ) +) + +fig.add_trace( + go.Scatter( + x=days_of_week, + y=total_bills, + yaxis="y2", + name="Total bill amount", + marker=dict(color="crimson"), + ) +) + +fig.update_layout( + legend=dict(orientation="h"), + xaxis=dict(showgrid=True, ticklen=10, tickwidth=3), + yaxis=dict( + title=dict(text="Total number of diners"), + side="left", + range=[0, 250], + ), + yaxis2=dict( + title=dict(text="Total bill amount"), + side="right", + range=[0, 2000], + overlaying="y", + tickmode="auto", + ), +) + +``` + #### Reference All of the y-axis properties are found here: https://plotly.com/python/reference/YAxis/. For more information on creating subplots see the [Subplots in Python](/python/subplots/) section. From e25b64344b5b2b5698eb52a204826455f6c0f781 Mon Sep 17 00:00:00 2001 From: Liam Connors Date: Thu, 19 Jan 2023 11:41:40 -0500 Subject: [PATCH 2/4] Update multiple-axes.md --- doc/python/multiple-axes.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/doc/python/multiple-axes.md b/doc/python/multiple-axes.md index 01eb0f7d367..649a302d149 100644 --- a/doc/python/multiple-axes.md +++ b/doc/python/multiple-axes.md @@ -360,7 +360,6 @@ fig.show() When you have multiple axes overlayed, each axis by default has its own number of ticks. You can sync the number of ticks on an axis overlayed on another axis by setting `tickmode="sync"`. In this example, we sync the ticks on the `"Total bill amount"` axis with the `"Total number of diners"` axis that it overlays. ```python -import pandas as pd import plotly.graph_objects as go from plotly.data import tips @@ -408,7 +407,7 @@ fig.update_layout( side="right", range=[0, 2000], overlaying="y", - tickmode="auto", + tickmode="sync", ), ) From fa9633ac599cf3e4f5af223ed5d2d3aca0628979 Mon Sep 17 00:00:00 2001 From: Liam Connors Date: Thu, 19 Jan 2023 11:53:59 -0500 Subject: [PATCH 3/4] Update multiple-axes.md --- doc/python/multiple-axes.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/python/multiple-axes.md b/doc/python/multiple-axes.md index 649a302d149..459614ba999 100644 --- a/doc/python/multiple-axes.md +++ b/doc/python/multiple-axes.md @@ -396,7 +396,6 @@ fig.add_trace( fig.update_layout( legend=dict(orientation="h"), - xaxis=dict(showgrid=True, ticklen=10, tickwidth=3), yaxis=dict( title=dict(text="Total number of diners"), side="left", @@ -411,6 +410,8 @@ fig.update_layout( ), ) +fig.show() + ``` #### Reference From 36cc0eae907a52c2bfbd0c23559a366dbc9cd9b4 Mon Sep 17 00:00:00 2001 From: Liam Connors Date: Thu, 19 Jan 2023 13:00:09 -0500 Subject: [PATCH 4/4] Update multiple-axes.md --- doc/python/multiple-axes.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/python/multiple-axes.md b/doc/python/multiple-axes.md index 459614ba999..9b2095a6389 100644 --- a/doc/python/multiple-axes.md +++ b/doc/python/multiple-axes.md @@ -354,10 +354,10 @@ fig.show() ### Sync Axes Ticks -*New in 5.13* +*New in 5.13* -When you have multiple axes overlayed, each axis by default has its own number of ticks. You can sync the number of ticks on an axis overlayed on another axis by setting `tickmode="sync"`. In this example, we sync the ticks on the `"Total bill amount"` axis with the `"Total number of diners"` axis that it overlays. +With overlayed axes, each axis by default has its own number of ticks. You can sync the number of ticks on a cartesian axis with another one it overlays by setting `tickmode="sync"`. In this example, we sync the ticks on the `"Total bill amount"` axis with the `"Total number of diners"` axis that it overlays. ```python import plotly.graph_objects as go