Skip to content

Commit b2ebf8b

Browse files
authored
Merge pull request #4307 from plotly/autorange-bounds
Docs for new range and autorange options + update Plotly.js version
2 parents 11b4936 + 871d065 commit b2ebf8b

File tree

121 files changed

+4846
-195
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

121 files changed

+4846
-195
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ This project adheres to [Semantic Versioning](http://semver.org/).
66

77
### Updated
88
- Improved json docstrings, added `BasePlotlyType.to_json()` method [[#4301](https://github.com/plotly/plotly.py/pull/4301)]
9+
- Updated Plotly.js from version 2.25.2 to version 2.26.0. See the [plotly.js CHANGELOG](https://github.com/plotly/plotly.js/blob/master/CHANGELOG.md#2260----2023-08-24) for more information. These changes are reflected in the auto-generated `plotly.graph_objects` module. Notable changes include:
10+
- Add "min", "max", "min reversed" and "max reversed" autorange options and handle partial ranges (i.e. one end being null), add `autorangeoptions` (`clipmin`, `clipmax`, `minallowed`, `maxallowed`, `include`) as well as `minallowed` and `maxallowed` to cartesian, gl3d and radial axes [[#6547](https://github.com/plotly/plotly.js/pull/6547)]
11+
- Add [n]-sigma (std deviations) box plots as an alternative to quartiles [[#6697](https://github.com/plotly/plotly.js/issues/6697)], with thanks to @28raining for the contribution!
12+
- Add "top left" & "top center" side options to legend title [[#6711](https://github.com/plotly/plotly.js/pull/6711)], with thanks to @28raining for the contribution!
13+
- Add "false" option to `scaleanchor` to allow removing a constraint that is set by default [[#6712](https://github.com/plotly/plotly.js/pull/6712)], with thanks to @lvlte for the contribution!
14+
915

1016
### Fixed
1117
- Fixed two issues with px.imshow: [[#4330](https://github.com/plotly/plotly.py/issues/4330)] when facet_col is an earlier dimension than animation_frame for xarrays and [[#4329](https://github.com/plotly/plotly.py/issues/4329)] when facet_col has string coordinates in xarrays [[#4331](https://github.com/plotly/plotly.py/pull/4331)]

doc/python/3d-axes.md

+37-8
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ jupyter:
55
text_representation:
66
extension: .md
77
format_name: markdown
8-
format_version: '1.1'
9-
jupytext_version: 1.1.1
8+
format_version: '1.3'
9+
jupytext_version: 1.15.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.7.3
23+
version: 3.10.4
2424
plotly:
2525
description: How to format axes of 3d plots in Python with Plotly.
2626
display_as: 3d_charts
@@ -41,6 +41,8 @@ set the range, title, ticks, color etc. of the axes.
4141

4242
For creating 3D charts, see [this page](https://plotly.com/python/3d-charts/).
4343

44+
Set `range` on an axis to manually configure a range for that axis. If you don't set `range`, it's automatically calculated. In this example, we set a `range` on `xaxis`, `yaxis`, and `zaxis`.
45+
4446
```python
4547
import plotly.graph_objects as go
4648
import numpy as np
@@ -66,6 +68,37 @@ fig.update_layout(
6668
fig.show()
6769
```
6870

71+
### Setting only a Lower or Upper Bound for Range
72+
73+
*New in 5.17*
74+
75+
You can also set just a lower or upper bound for `range`. In this case, autorange is used for the other bound. In this example, we apply autorange to the lower bound of the `yaxis` and the upper bound of `zaxis` by setting them to `None`.
76+
77+
```python
78+
import plotly.graph_objects as go
79+
import numpy as np
80+
np.random.seed(1)
81+
82+
N = 70
83+
84+
fig = go.Figure(data=[go.Mesh3d(x=(70*np.random.randn(N)),
85+
y=(55*np.random.randn(N)),
86+
z=(40*np.random.randn(N)),
87+
opacity=0.5,
88+
color='rgba(244,22,100,0.6)'
89+
)])
90+
91+
fig.update_layout(
92+
scene = dict(
93+
xaxis = dict(nticks=4, range=[-100,100],),
94+
yaxis = dict(nticks=4, range=[None, 100],),
95+
zaxis = dict(nticks=4, range=[-100, None],),),
96+
width=700,
97+
margin=dict(r=20, l=10, b=10, t=10))
98+
99+
fig.show()
100+
```
101+
69102
### Fixed Ratio Axes
70103

71104
```python
@@ -226,7 +259,3 @@ fig.update_layout(scene=dict(xaxis_showspikes=False,
226259
yaxis_showspikes=False))
227260
fig.show()
228261
```
229-
230-
```python
231-
232-
```

doc/python/axes.md

+143-54
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ jupyter:
66
extension: .md
77
format_name: markdown
88
format_version: '1.3'
9-
jupytext_version: 1.14.1
9+
jupytext_version: 1.15.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.10.4
2424
plotly:
2525
description: How to adjust axes properties in Python - axes titles, styling and
2626
coloring axes and grid lines, ticks, tick labels and more.
@@ -544,7 +544,7 @@ fig.show()
544544

545545
#### Setting the Range of Axes Manually
546546

547-
The visible x and y axis range can be configured manually by setting the `range` axis property to a list of two values, the lower and upper boundary.
547+
The visible x and y axis range can be configured manually by setting the `range` axis property to a list of two values, the lower and upper bound.
548548

549549
Here's an example of manually specifying the x and y axis range for a faceted scatter plot created with Plotly Express.
550550

@@ -559,6 +559,41 @@ fig.update_yaxes(range=[3, 9])
559559
fig.show()
560560
```
561561

562+
#### Setting only a Lower or Upper Bound for Range
563+
564+
*New in 5.17*
565+
566+
You can also set just a lower or upper bound manually and have autorange applied to the other bound by setting it to `None`. In the following example, we set a an upper bound of 4.5 on the x axes, while specifying `None` for the lower bound, meaning it will use autorange. On the y axes, we set the lower bound, and use `None` for the upper bound, meaning that uses autorange.
567+
568+
```python
569+
import plotly.express as px
570+
df = px.data.iris()
571+
572+
fig = px.scatter(df, x="sepal_width", y="sepal_length", facet_col="species")
573+
fig.update_xaxes(range=[None, 4.5])
574+
fig.update_yaxes(range=[3, None])
575+
576+
fig.show()
577+
```
578+
579+
#### Setting a Maximum and Minimum Allowed Axis Value
580+
581+
*New in 5.17*
582+
583+
When setting a range manually, you can also set a `maxallowed` or `minallowed` for an axis. With this set, you won't be able to pan further than the min or max allowed. In this example, we've set the minimum allowed on the x-axis to 1 and the maximum allowed on the y-axis to 10.
584+
585+
```python
586+
import plotly.express as px
587+
588+
df = px.data.iris()
589+
590+
fig = px.scatter(df, x="sepal_width", y="sepal_length")
591+
fig.update_xaxes(range=[1.5, 4.5], minallowed=1)
592+
fig.update_yaxes(range=[3, 9], maxallowed=10)
593+
594+
fig.show()
595+
```
596+
562597
#### Disabling Pan/Zoom on Axes (Fixed Range)
563598

564599
Pan/Zoom can be disabled for a given axis by setting `fixedrange` to `True`.
@@ -658,37 +693,6 @@ fig.update_yaxes(
658693
)
659694

660695

661-
fig.show()
662-
```
663-
664-
### Fixed Ratio Axes with Compressed domain
665-
666-
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".
667-
668-
```python
669-
import plotly.graph_objects as go
670-
671-
fig = go.Figure()
672-
673-
fig.add_trace(go.Scatter(
674-
x = [0,1,1,0,0,1,1,2,2,3,3,2,2,3],
675-
y = [0,0,1,1,3,3,2,2,3,3,1,1,0,0]
676-
))
677-
678-
fig.update_layout(
679-
width = 800,
680-
height = 500,
681-
title = "fixed-ratio axes with compressed axes"
682-
)
683-
fig.update_xaxes(
684-
range=[-1,4], # sets the range of xaxis
685-
constrain="domain", # meanwhile compresses the xaxis by decreasing its "domain"
686-
)
687-
fig.update_yaxes(
688-
scaleanchor = "x",
689-
scaleratio = 1,
690-
)
691-
692696
fig.show()
693697
```
694698

@@ -724,6 +728,36 @@ fig.update_yaxes(range=[9, 3])
724728
fig.show()
725729
```
726730

731+
*New in 5.17*
732+
733+
To use a reversed axis while specifying only a lower bound for the range, set `autorange="min reversed"`:
734+
735+
```python
736+
import plotly.express as px
737+
738+
df = px.data.iris()
739+
740+
fig = px.scatter(df, x="sepal_width", y="sepal_length", facet_col="species")
741+
fig.update_yaxes(range=[9, None], autorange="min reversed")
742+
743+
fig.show()
744+
```
745+
746+
*New in 5.17*
747+
748+
To use a reversed axis while specifying only an upper bound for the range, set `autorange="max reversed"`:
749+
750+
```python
751+
import plotly.express as px
752+
753+
df = px.data.iris()
754+
755+
fig = px.scatter(df, x="sepal_width", y="sepal_length", facet_col="species")
756+
fig.update_yaxes(range=[None, 3], autorange="max reversed")
757+
758+
fig.show()
759+
```
760+
727761
### Axis range for log axis type
728762

729763
If you are using a `log` type of axis and you want to set the range of the axis, you have to give the `log10` value of the bounds when using `fig.update_xaxes` or `fig.update_layout`. However, with `plotly.express` functions you pass directly the values of the range bounds (`plotly.express` then computes the appropriate values to pass to the figure layout).
@@ -748,25 +782,6 @@ fig.update_yaxes(type="log")
748782
fig.show()
749783
```
750784

751-
#### <code>nonnegative</code>, <code>tozero</code>, and <code>normal</code> Rangemode
752-
753-
The axis auto-range calculation logic can be configured using the `rangemode` axis parameter.
754-
755-
If `rangemode` is `"normal"` (the default), the range is computed based on the min and max values of the input data. If `"tozero"`, the range will always include zero. If `"nonnegative"`, the range will not extend below zero, regardless of the input data.
756-
757-
Here is an example of configuring a faceted scatter plot created using Plotly Express to always include zero for both the x and y axes.
758-
759-
```python
760-
import plotly.express as px
761-
df = px.data.iris()
762-
763-
fig = px.scatter(df, x="sepal_width", y="sepal_length", facet_col="species")
764-
fig.update_xaxes(rangemode="tozero")
765-
fig.update_yaxes(rangemode="tozero")
766-
767-
fig.show()
768-
```
769-
770785
#### Setting the domain of the axis
771786

772787
```python
@@ -804,6 +819,80 @@ fig.update_xaxes(matches='x')
804819
fig.show()
805820
```
806821

822+
#### <code>nonnegative</code>, <code>tozero</code>, and <code>normal</code> Rangemode
823+
824+
When you don't specify a range, autorange is used. It's also used for bounds set to `None` when providing a `range`.
825+
826+
The axis auto-range calculation logic can be configured using the `rangemode` axis parameter.
827+
828+
If `rangemode` is `"normal"` (the default), the range is computed based on the min and max values of the input data. If `"tozero"`, the range will always include zero. If `"nonnegative"`, the range will not extend below zero, regardless of the input data.
829+
830+
Here is an example of configuring a faceted scatter plot created using Plotly Express to always include zero for both the x and y axes.
831+
832+
```python
833+
import plotly.express as px
834+
df = px.data.iris()
835+
836+
fig = px.scatter(df, x="sepal_width", y="sepal_length", facet_col="species")
837+
fig.update_xaxes(rangemode="tozero")
838+
fig.update_yaxes(rangemode="tozero")
839+
840+
fig.show()
841+
```
842+
843+
#### Autorange Options
844+
845+
*New in 5.17*
846+
847+
You can further configure how autorange is applied using `autorangeoptions` to specify maximum or minimum values or values to include.
848+
849+
##### Specifying Minimum and Maximum Allowed Values
850+
851+
Using `autorangeoptions.maxallowed`, you can specify an exact value to use as the autorange maximum. With `autorangeoptions.minallowed`, you can specify an exact value to use as the autorange minimum.
852+
853+
```python
854+
import plotly.express as px
855+
856+
df = px.data.iris()
857+
858+
fig = px.scatter(df, x="sepal_width", y="sepal_length")
859+
fig.update_yaxes(autorangeoptions=dict(minallowed=3))
860+
fig.update_xaxes(autorangeoptions=dict(maxallowed=5))
861+
862+
fig.show()
863+
```
864+
865+
##### Clip Minimum and Maximum
866+
867+
You can also clip an axis range at a specific maximum or minimum value with `autorangeoptions.clipmax` and `autorangeoptions.clipmin`.
868+
869+
```python
870+
import plotly.express as px
871+
872+
df = px.data.iris()
873+
874+
fig = px.scatter(df, x="sepal_width", y="sepal_length")
875+
fig.update_yaxes(autorangeoptions=dict(clipmin=5))
876+
fig.update_xaxes(autorangeoptions=dict(clipmax=4))
877+
878+
fig.show()
879+
```
880+
881+
##### Specify Values to be Included
882+
883+
Use `autorangeoptions.include` to specify a value that should always be included within the calculated autorange. In this example, we specify that for the autorange calculated on the x-axis, 5 should be included.
884+
885+
```python
886+
import plotly.express as px
887+
888+
df = px.data.iris()
889+
890+
fig = px.scatter(df, x="sepal_width", y="sepal_length")
891+
fig.update_xaxes(autorangeoptions=dict(include=5))
892+
893+
fig.show()
894+
```
895+
807896
#### Reference
808897

809898
See https://plotly.com/python/reference/layout/xaxis/ and https://plotly.com/python/reference/layout/yaxis/ for more information and chart attribute options!

packages/javascript/jupyterlab-plotly/package-lock.json

+7-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/javascript/jupyterlab-plotly/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
"@lumino/messaging": "^1.2.3",
6666
"@lumino/widgets": "^1.8.1",
6767
"lodash": "^4.17.4",
68-
"plotly.js": "^2.25.2"
68+
"plotly.js": "^2.26.0"
6969
},
7070
"jupyterlab": {
7171
"extension": "lib/jupyterlab-plugin",

0 commit comments

Comments
 (0)