@@ -5601,69 +5601,139 @@ def test_plot_columns_cycle_deprecation():
5601
5601
plt .plot (np .zeros ((2 , 2 )), np .zeros ((2 , 3 )))
5602
5602
5603
5603
5604
- # def test_share_symmetric():
5605
- # fig = plt.figure()
5606
- # ax1 = fig.add_subplot(211)
5607
- # ax2 = fig.add_subplot(212)
5608
- #
5609
- # ax1.share_x_axes(ax2, symmetric=True, transitive=False)
5610
-
5611
- #
5612
- # def test_share_unshare_3d_axes():
5613
- # fig = plt.figure()
5614
- # ax1 = fig.add_subplot(211, projection="3d")
5615
- # ax2 = fig.add_subplot(212, projection="3d",
5616
- # sharex=ax1,
5617
- # sharey=ax1,
5618
- # sharez=ax1)
5619
- #
5620
- # # Testing unsharing
5621
- # ax1.unshare_axes()
5622
- # assert ax2._sharex is None
5623
- # assert ax2._sharey is None
5624
- # assert ax2._sharez is None
5625
- #
5626
- # sharedx = ax2._shared_x_axes
5627
- # sharedy = ax2._shared_y_axes
5628
- # sharedz = ax2._shared_z_axes
5629
- #
5630
- # assert ax1 not in sharedx
5631
- # assert ax1 not in sharedy
5632
- # assert ax1 not in sharedz
5633
- #
5634
- # sharedx = ax1._shared_x_axes
5635
- # sharedy = ax1._shared_y_axes
5636
- # sharedz = ax1._shared_z_axes
5637
- #
5638
- # assert ax2 not in sharedx
5639
- # assert ax2 not in sharedy
5640
- # assert ax2 not in sharedz
5641
- #
5642
- # # Testing sharing
5643
- #
5644
- # # x axis
5645
- # ax1.share_x_axes(ax2)
5646
- #
5647
- # sharedx = ax1._shared_x_axes
5648
- # assert ax2 in sharedx
5649
- #
5650
- # sharedx = ax2._shared_x_axes
5651
- # assert ax1 in sharedx
5652
- #
5653
- # # y axis
5654
- # ax2.share_y_axes(ax1)
5655
- #
5656
- # sharedy = ax1._shared_y_axes
5657
- # assert ax2 in sharedy
5658
- #
5659
- # sharedy = ax2._shared_y_axes
5660
- # assert ax1 in sharedy
5661
- #
5662
- # # z axis
5663
- # ax1.share_z_axes(ax2)
5664
- #
5665
- # sharedz = ax2._shared_z_axes
5666
- # assert ax1 in sharedz
5667
- #
5668
- # sharedz = ax1._shared_z_axes
5669
- # assert ax2 in sharedz
5604
+ def _symmetric (A , B , shared_axes ):
5605
+ # Symmetric test between A and C
5606
+ C = B in getattr (A , "get_shared_{}_axes" .format (shared_axes ))()
5607
+ C &= A in getattr (B , "get_shared_{}_axes" .format (shared_axes ))()
5608
+ C &= B in getattr (A , "get_shared_{}_inv_axes" .format (shared_axes ))()
5609
+ C &= A in getattr (B , "get_shared_{}_inv_axes" .format (shared_axes ))()
5610
+ return C
5611
+
5612
+
5613
+ def _no_relation (A , B , shared_axes ):
5614
+ # Symmetric test between A and C
5615
+ C = B not in getattr (A , "get_shared_{}_axes" .format (shared_axes ))()
5616
+ C &= A not in getattr (B , "get_shared_{}_axes" .format (shared_axes ))()
5617
+ C &= B not in getattr (A , "get_shared_{}_inv_axes" .format (shared_axes ))()
5618
+ C &= A not in getattr (B , "get_shared_{}_inv_axes" .format (shared_axes ))()
5619
+ return C
5620
+
5621
+
5622
+ def _asymmetric (A , B , shared_axes ):
5623
+ # A -> B but not B -> A
5624
+ C = B in getattr (A , "get_shared_{}_axes" .format (shared_axes ))()
5625
+ C &= A not in getattr (B , "get_shared_{}_axes" .format (shared_axes ))()
5626
+ C &= A in getattr (B , "get_shared_{}_inv_axes" .format (shared_axes ))()
5627
+ C &= B not in getattr (A , "get_shared_{}_inv_axes" .format (shared_axes ))()
5628
+ return C
5629
+
5630
+
5631
+ def test_share_transitive ():
5632
+ axes = ["x" , "y" ]
5633
+
5634
+ for ax in axes :
5635
+ fig = plt .figure ()
5636
+ A = fig .add_subplot (411 )
5637
+ B = fig .add_subplot (412 )
5638
+ C = fig .add_subplot (413 )
5639
+ D = fig .add_subplot (414 )
5640
+
5641
+ # C -> D
5642
+ share = getattr (C , "share_{}_axes" .format (ax ))
5643
+ share (D , symmetric = False , transitive = False )
5644
+
5645
+ # A -> B
5646
+ share = getattr (A , "share_{}_axes" .format (ax ))
5647
+ share (B , symmetric = False , transitive = False )
5648
+
5649
+ # A -> C, C -> A, C -> B, A -> D
5650
+ share (C , symmetric = True , transitive = True )
5651
+
5652
+ # Symmetric test between A and C
5653
+ assert _symmetric (A , C , ax )
5654
+
5655
+ # A -> B but not B -> C
5656
+ assert _asymmetric (A , B , ax )
5657
+
5658
+ # C -> B but not B -> C
5659
+ assert _asymmetric (C , B , ax )
5660
+
5661
+ # A -> D but not D -> D
5662
+ assert _asymmetric (A , D , ax )
5663
+
5664
+ # C -> D but not D -> C
5665
+ assert _asymmetric (C , D , ax )
5666
+
5667
+ assert _no_relation (B , D , ax )
5668
+
5669
+ plt .close (fig )
5670
+
5671
+
5672
+ def test_share_transitive1 ():
5673
+ axes = ["x" , "y" ]
5674
+
5675
+ for ax in axes :
5676
+ fig = plt .figure ()
5677
+ A = fig .add_subplot (411 )
5678
+ B = fig .add_subplot (412 )
5679
+ C = fig .add_subplot (413 )
5680
+ D = fig .add_subplot (414 )
5681
+
5682
+ # C -> D
5683
+ share = getattr (C , "share_{}_axes" .format (ax ))
5684
+ share (D , symmetric = False , transitive = False )
5685
+
5686
+ # A -> B
5687
+ share = getattr (A , "share_{}_axes" .format (ax ))
5688
+ share (B , symmetric = False , transitive = False )
5689
+
5690
+ # A -> C, A -> D
5691
+ share (C , symmetric = False , transitive = True )
5692
+
5693
+ # A -> C but not C -> A
5694
+ assert _asymmetric (A , C , ax )
5695
+
5696
+ # A -> B but not B -> C
5697
+ assert _asymmetric (A , B , ax )
5698
+
5699
+ # A -> D but not D -> A
5700
+ assert _asymmetric (A , D , ax )
5701
+
5702
+ # C -> D but not D -> C
5703
+ assert _asymmetric (C , D , ax )
5704
+
5705
+ assert _no_relation (B , D , ax )
5706
+ assert _no_relation (B , C , ax )
5707
+
5708
+ plt .close (fig )
5709
+
5710
+
5711
+ def test_share_symmetric ():
5712
+ axes = ["x" , "y" ]
5713
+
5714
+ for ax in axes :
5715
+ fig = plt .figure ()
5716
+ A = fig .add_subplot (211 )
5717
+ B = fig .add_subplot (212 )
5718
+
5719
+ share = getattr (A , "share_{}_axes" .format (ax ))
5720
+ # A -> B but not B -> A
5721
+ share (B , symmetric = False , transitive = False )
5722
+ assert _asymmetric (A , B , ax )
5723
+ plt .close (fig )
5724
+
5725
+
5726
+ def test_share_symmetric1 ():
5727
+ axes = ["x" , "y" ]
5728
+
5729
+ for ax in axes :
5730
+ fig = plt .figure ()
5731
+ A = fig .add_subplot (211 )
5732
+ B = fig .add_subplot (212 )
5733
+
5734
+ share = getattr (A , "share_{}_axes" .format (ax ))
5735
+ # A -> B, B -> A
5736
+ share (B , symmetric = True , transitive = False )
5737
+ assert _symmetric (A , B , ax )
5738
+
5739
+ plt .close (fig )
0 commit comments