File tree 2 files changed +21
-1
lines changed
2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change 2
2
import decimal
3
3
import json as _json
4
4
import sys
5
+ import re
5
6
6
7
import pytz
7
8
@@ -242,3 +243,18 @@ def _decorator(func):
242
243
func .__doc__ = func .__doc__ .format (** names )
243
244
return func
244
245
return _decorator
246
+
247
+
248
+ def _natural_sort_strings (vals , reverse = False ):
249
+
250
+ def key (v ):
251
+ v_parts = re .split (r'(\d+)' , v )
252
+ for i in range (len (v_parts )):
253
+ try :
254
+ v_parts [i ] = int (v_parts [i ])
255
+ except ValueError :
256
+ # not an int
257
+ pass
258
+ return tuple (v_parts )
259
+
260
+ return sorted (vals , key = key , reverse = reverse )
Original file line number Diff line number Diff line change 9
9
from contextlib import contextmanager
10
10
from copy import deepcopy , copy
11
11
12
+ from _plotly_utils .utils import _natural_sort_strings
12
13
from plotly .subplots import (
13
14
_set_trace_grid_reference ,
14
15
_get_grid_subplot ,
@@ -810,7 +811,10 @@ def _select_layout_subplots_by_prefix(
810
811
else :
811
812
container_to_row_col = None
812
813
813
- for k in self .layout :
814
+ # Natural sort keys so that xaxis20 is after xaxis3
815
+ layout_keys = _natural_sort_strings (list (self .layout ))
816
+
817
+ for k in layout_keys :
814
818
if k .startswith (prefix ) and self .layout [k ] is not None :
815
819
816
820
# Filter by row/col
You can’t perform that action at this time.
0 commit comments