Skip to content

Commit 3ce7998

Browse files
jingw222emmanuelle
authored andcommitted
Add an example with constrain='domain' (#2025)
Add a following example demonstrating Fixed Ratio Axes with Compressed domain to (axes tutorial)[https://plot.ly/python/axes/].
1 parent b6932d5 commit 3ce7998

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

Diff for: doc/python/axes.md

+31
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,37 @@ fig.update_layout(
481481
fig.show()
482482
```
483483

484+
### Fixed Ratio Axes with Compressed domain
485+
486+
If an axis needs to be compressed (either due to its own `scaleanchor` and `scaleratio` or those of the other axis), `constrain` determines how that happens: by increasing the "range" (default), or by decreasing the "domain".
487+
488+
```python
489+
import plotly.graph_objects as go
490+
491+
fig = go.Figure()
492+
493+
fig.add_trace(go.Scatter(
494+
x = [0,1,1,0,0,1,1,2,2,3,3,2,2,3],
495+
y = [0,0,1,1,3,3,2,2,3,3,1,1,0,0]
496+
))
497+
498+
fig.update_layout(
499+
width = 800,
500+
height = 500,
501+
title = "fixed-ratio axes with compressed axes",
502+
xaxis = dict(
503+
range=[-1,4], # sets the range of xaxis
504+
constrain="domain", # meanwhile compresses the xaxis by decreasing its "domain"
505+
),
506+
yaxis = dict(
507+
scaleanchor = "x",
508+
scaleratio = 1,
509+
),
510+
)
511+
512+
fig.show()
513+
```
514+
484515
#### Reversed Axes
485516

486517
You can tell plotly's automatic axis range calculation logic to reverse the direction of an axis by setting the `autorange` axis property to `"reversed"`.

0 commit comments

Comments
 (0)