Skip to content

Commit 139d42c

Browse files
committed
Update multiple-axes.md
1 parent 179e0d8 commit 139d42c

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

Diff for: doc/python/multiple-axes.md

+62
Original file line numberDiff line numberDiff line change
@@ -352,5 +352,67 @@ fig.show()
352352

353353
```
354354

355+
### Sync Axes Ticks
356+
357+
*New in 5.13*
358+
359+
360+
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.
361+
362+
```python
363+
import pandas as pd
364+
import plotly.graph_objects as go
365+
from plotly.data import tips
366+
367+
df = tips()
368+
369+
summed_values = df.groupby(by="day", as_index=False).sum(numeric_only=True)
370+
day_order_mapping = {"Thur": 0, "Fri": 1, "Sat": 2, "Sun": 3}
371+
summed_values["order"] = summed_values["day"].apply(lambda day: day_order_mapping[day])
372+
summed_values = summed_values.sort_values(by="order")
373+
374+
days_of_week = summed_values["day"].values
375+
total_bills = summed_values["total_bill"].values
376+
number_of_diners = summed_values["size"].values
377+
378+
379+
fig = go.Figure(
380+
data=go.Bar(
381+
x=days_of_week,
382+
y=number_of_diners,
383+
name="Total number of diners",
384+
marker=dict(color="paleturquoise"),
385+
)
386+
)
387+
388+
fig.add_trace(
389+
go.Scatter(
390+
x=days_of_week,
391+
y=total_bills,
392+
yaxis="y2",
393+
name="Total bill amount",
394+
marker=dict(color="crimson"),
395+
)
396+
)
397+
398+
fig.update_layout(
399+
legend=dict(orientation="h"),
400+
xaxis=dict(showgrid=True, ticklen=10, tickwidth=3),
401+
yaxis=dict(
402+
title=dict(text="Total number of diners"),
403+
side="left",
404+
range=[0, 250],
405+
),
406+
yaxis2=dict(
407+
title=dict(text="Total bill amount"),
408+
side="right",
409+
range=[0, 2000],
410+
overlaying="y",
411+
tickmode="auto",
412+
),
413+
)
414+
415+
```
416+
355417
#### Reference
356418
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.

0 commit comments

Comments
 (0)