Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ac0831b

Browse files
Update multiple-axes.md
1 parent 1254d9f commit ac0831b

File tree

1 file changed

+103
-2
lines changed

1 file changed

+103
-2
lines changed

‎doc/python/multiple-axes.md‎

Lines changed: 103 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jupyter:
88
format_version: '1.3'
99
jupytext_version: 1.14.1
1010
kernelspec:
11-
display_name: Python 3
11+
display_name: Python 3 (ipykernel)
1212
language: python
1313
name: python3
1414
language_info:
@@ -20,7 +20,7 @@ jupyter:
2020
name: python
2121
nbconvert_exporter: python
2222
pygments_lexer: ipython3
23-
version: 3.8.8
23+
version: 3.8.0
2424
plotly:
2525
description: How to make a graph with multiple axes (dual y-axis plots, plots
2626
with secondary axes) in python.
@@ -249,5 +249,106 @@ fig.update_layout(
249249
fig.show()
250250
```
251251

252+
#### Automatically Shifting Axes
253+
254+
To automatically reposition axes to avoid overlap with other axes with the same `overlaying` value, set `autoshift=True`. For `autoshift` to work on an axis, you'll also need to set `anchor="free"` on that axis.
255+
256+
```python
257+
import plotly.graph_objects as go
258+
259+
fig = go.Figure()
260+
261+
fig.add_trace(go.Scatter(x=[1, 2, 3], y=[4, 5, 6], name="yaxis data"))
262+
263+
264+
fig.add_trace(go.Scatter(x=[2, 3, 4], y=[40, 50, 60], name="yaxis2 data", yaxis="y2"))
265+
266+
fig.add_trace(
267+
go.Scatter(x=[4, 5, 6], y=[1000, 2000, 3000], name="yaxis3 data", yaxis="y3")
268+
)
269+
270+
fig.add_trace(
271+
go.Scatter(x=[3, 4, 5], y=[400, 500, 600], name="yaxis4 data", yaxis="y4")
272+
)
273+
274+
275+
fig.update_layout(
276+
xaxis=dict(domain=[0.25, 0.75]),
277+
yaxis=dict(
278+
title="yaxis title",
279+
),
280+
yaxis2=dict(
281+
title="yaxis2 title",
282+
overlaying="y",
283+
side="right",
284+
),
285+
yaxis3=dict(title="yaxis3 title", anchor="free", overlaying="y", autoshift=True),
286+
yaxis4=dict(
287+
title="yaxis4 title",
288+
anchor="free",
289+
overlaying="y",
290+
autoshift=True,
291+
),
292+
)
293+
294+
fig.update_layout(
295+
title_text="Shifting y-axes with autoshift",
296+
)
297+
298+
fig.show()
299+
300+
```
301+
302+
### Shift Axes by a Specific Number of Pixels
303+
304+
Set a `shift` value on an axis to shift an axis by that number of pixels. A positive value shifts an axis to the right. A negative value shifts it to the left. Here, we shift `yaxis4` 100 pixels further to the left.
305+
306+
```python
307+
import plotly.graph_objects as go
308+
309+
fig = go.Figure()
310+
311+
fig.add_trace(go.Scatter(x=[1, 2, 3], y=[4, 5, 6], name="yaxis data"))
312+
313+
314+
fig.add_trace(go.Scatter(x=[2, 3, 4], y=[40, 50, 60], name="yaxis2 data", yaxis="y2"))
315+
316+
fig.add_trace(
317+
go.Scatter(x=[4, 5, 6], y=[1000, 2000, 3000], name="yaxis3 data", yaxis="y3")
318+
)
319+
320+
fig.add_trace(
321+
go.Scatter(x=[3, 4, 5], y=[400, 500, 600], name="yaxis4 data", yaxis="y4")
322+
)
323+
324+
325+
fig.update_layout(
326+
xaxis=dict(domain=[0.25, 0.75]),
327+
yaxis=dict(
328+
title="yaxis title",
329+
),
330+
yaxis2=dict(
331+
title="yaxis2 title",
332+
overlaying="y",
333+
side="right",
334+
),
335+
yaxis3=dict(title="yaxis3 title", anchor="free", overlaying="y", autoshift=True),
336+
yaxis4=dict(
337+
title="yaxis4 title",
338+
anchor="free",
339+
overlaying="y",
340+
autoshift=True,
341+
shift=-100,
342+
),
343+
)
344+
345+
fig.update_layout(
346+
title_text="Shifting y-axes by a specific number of pixels",
347+
)
348+
349+
fig.show()
350+
351+
```
352+
252353
#### Reference
253354
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)

AltStyle によって変換されたページ (->オリジナル) /