@@ -754,8 +754,10 @@ def _check_hv_spacing(dimsize, spacing, name, dimvarname, dimname):
754754 )
755755 grid_ref [r ][c ] = subplot_refs
756756
757- _configure_shared_axes (layout , grid_ref , specs , "x" , shared_xaxes , row_dir )
758- _configure_shared_axes (layout , grid_ref , specs , "y" , shared_yaxes , row_dir )
757+ _configure_shared_axes (layout , grid_ref , specs , "x" , shared_xaxes , row_dir , False )
758+ _configure_shared_axes (layout , grid_ref , specs , "y" , shared_yaxes , row_dir , False )
759+ if secondary_y :
760+ _configure_shared_axes (layout , grid_ref , specs , "y" , shared_yaxes , row_dir , True )
759761
760762 # Build inset reference
761763 # ---------------------
@@ -887,7 +889,7 @@ def _check_hv_spacing(dimsize, spacing, name, dimvarname, dimname):
887889 return figure
888890
889891
890- def _configure_shared_axes (layout , grid_ref , specs , x_or_y , shared , row_dir ):
892+ def _configure_shared_axes (layout , grid_ref , specs , x_or_y , shared , row_dir , secondary_y ):
891893 rows = len (grid_ref )
892894 cols = len (grid_ref [0 ])
893895
@@ -898,6 +900,13 @@ def _configure_shared_axes(layout, grid_ref, specs, x_or_y, shared, row_dir):
898900 else :
899901 rows_iter = range (rows )
900902
903+ if secondary_y :
904+ cols_iter = range (cols - 1 , - 1 , - 1 )
905+ axis_index = 1
906+ else :
907+ cols_iter = range (cols )
908+ axis_index = 0
909+
901910 def update_axis_matches (first_axis_id , subplot_ref , spec , remove_label ):
902911 if subplot_ref is None :
903912 return first_axis_id
@@ -921,13 +930,15 @@ def update_axis_matches(first_axis_id, subplot_ref, spec, remove_label):
921930 return first_axis_id
922931
923932 if shared == "columns" or (x_or_y == "x" and shared is True ):
924- for c in range ( cols ) :
933+ for c in cols_iter :
925934 first_axis_id = None
926935 ok_to_remove_label = x_or_y == "x"
927936 for r in rows_iter :
928937 if not grid_ref [r ][c ]:
929938 continue
930- subplot_ref = grid_ref [r ][c ][0 ]
939+ if axis_index >= len (grid_ref [r ][c ]):
940+ continue
941+ subplot_ref = grid_ref [r ][c ][axis_index ]
931942 spec = specs [r ][c ]
932943 first_axis_id = update_axis_matches (
933944 first_axis_id , subplot_ref , spec , ok_to_remove_label
@@ -937,26 +948,30 @@ def update_axis_matches(first_axis_id, subplot_ref, spec, remove_label):
937948 for r in rows_iter :
938949 first_axis_id = None
939950 ok_to_remove_label = x_or_y == "y"
940- for c in range ( cols ) :
951+ for c in cols_iter :
941952 if not grid_ref [r ][c ]:
942953 continue
943- subplot_ref = grid_ref [r ][c ][0 ]
954+ if axis_index >= len (grid_ref [r ][c ]):
955+ continue
956+ subplot_ref = grid_ref [r ][c ][axis_index ]
944957 spec = specs [r ][c ]
945958 first_axis_id = update_axis_matches (
946959 first_axis_id , subplot_ref , spec , ok_to_remove_label
947960 )
948961
949962 elif shared == "all" :
950963 first_axis_id = None
951- for c in range ( cols ):
952- for ri , r in enumerate ( rows_iter ) :
964+ for ri , r in enumerate ( rows_iter ):
965+ for c in cols_iter :
953966 if not grid_ref [r ][c ]:
954967 continue
955- subplot_ref = grid_ref [r ][c ][0 ]
968+ if axis_index >= len (grid_ref [r ][c ]):
969+ continue
970+ subplot_ref = grid_ref [r ][c ][axis_index ]
956971 spec = specs [r ][c ]
957972
958973 if x_or_y == "y" :
959- ok_to_remove_label = c > 0
974+ ok_to_remove_label = c < cols - 1 if secondary_y else c > 0
960975 else :
961976 ok_to_remove_label = ri > 0 if row_dir > 0 else r < rows - 1
962977
0 commit comments