MCPcopy Index your code
hub / github.com/plotly/plotly.py / _configure_shared_axes

Function _configure_shared_axes

plotly/_subplots.py:897–987  ·  view source on GitHub ↗
(
    layout, grid_ref, specs, x_or_y, shared, row_dir, secondary_y
)

Source from the content-addressed store, hash-verified

895
896
897def _configure_shared_axes(
898 layout, grid_ref, specs, x_or_y, shared, row_dir, secondary_y
899):
900 rows = len(grid_ref)
901 cols = len(grid_ref[0])
902
903 layout_key_ind = ["x", "y"].index(x_or_y)
904
905 if row_dir < 0:
906 rows_iter = range(rows - 1, -1, -1)
907 else:
908 rows_iter = range(rows)
909
910 if secondary_y:
911 cols_iter = range(cols - 1, -1, -1)
912 axis_index = 1
913 else:
914 cols_iter = range(cols)
915 axis_index = 0
916
917 def update_axis_matches(first_axis_id, subplot_ref, spec, remove_label):
918 if subplot_ref is None:
919 return first_axis_id
920
921 if x_or_y == "x":
922 span = spec["colspan"]
923 else:
924 span = spec["rowspan"]
925
926 if subplot_ref.subplot_type == "xy" and span == 1:
927 if first_axis_id is None:
928 first_axis_name = subplot_ref.layout_keys[layout_key_ind]
929 first_axis_id = first_axis_name.replace("axis", "")
930 else:
931 axis_name = subplot_ref.layout_keys[layout_key_ind]
932 axis_to_match = layout[axis_name]
933 axis_to_match.matches = first_axis_id
934 if remove_label:
935 axis_to_match.showticklabels = False
936
937 return first_axis_id
938
939 if shared == "columns" or (x_or_y == "x" and shared is True):
940 for c in cols_iter:
941 first_axis_id = None
942 ok_to_remove_label = x_or_y == "x"
943 for r in rows_iter:
944 if not grid_ref[r][c]:
945 continue
946 if axis_index >= len(grid_ref[r][c]):
947 continue
948 subplot_ref = grid_ref[r][c][axis_index]
949 spec = specs[r][c]
950 first_axis_id = update_axis_matches(
951 first_axis_id, subplot_ref, spec, ok_to_remove_label
952 )
953
954 elif shared == "rows" or (x_or_y == "y" and shared is True):

Callers 1

make_subplotsFunction · 0.85

Calls 1

update_axis_matchesFunction · 0.85

Tested by

no test coverage detected