@@ -1108,3 +1108,50 @@ def test_mixed_collection():
11081108
11091109 ax .set_xlim (0 , 16 )
11101110 ax .set_ylim (0 , 16 )
1111+
1112+
1113+ @image_comparison (baseline_images = ['twin_spines' ], remove_text = True ,
1114+ extensions = ['png' ])
1115+ def test_twin_spines ():
1116+
1117+ def make_patch_spines_invisible (ax ):
1118+ ax .set_frame_on (True )
1119+ ax .patch .set_visible (False )
1120+ for sp in ax .spines .itervalues ():
1121+ sp .set_visible (False )
1122+
1123+ fig = plt .figure (figsize = (4 , 3 ))
1124+ fig .subplots_adjust (right = 0.75 )
1125+
1126+ host = fig .add_subplot (111 )
1127+ par1 = host .twinx ()
1128+ par2 = host .twinx ()
1129+
1130+ # Offset the right spine of par2. The ticks and label have already been
1131+ # placed on the right by twinx above.
1132+ par2 .spines ["right" ].set_position (("axes" , 1.2 ))
1133+ # Having been created by twinx, par2 has its frame off, so the line of its
1134+ # detached spine is invisible. First, activate the frame but make the patch
1135+ # and spines invisible.
1136+ make_patch_spines_invisible (par2 )
1137+ # Second, show the right spine.
1138+ par2 .spines ["right" ].set_visible (True )
1139+
1140+ p1 , = host .plot ([0 , 1 , 2 ], [0 , 1 , 2 ], "b-" )
1141+ p2 , = par1 .plot ([0 , 1 , 2 ], [0 , 3 , 2 ], "r-" )
1142+ p3 , = par2 .plot ([0 , 1 , 2 ], [50 , 30 , 15 ], "g-" )
1143+
1144+ host .set_xlim (0 , 2 )
1145+ host .set_ylim (0 , 2 )
1146+ par1 .set_ylim (0 , 4 )
1147+ par2 .set_ylim (1 , 65 )
1148+
1149+ host .yaxis .label .set_color (p1 .get_color ())
1150+ par1 .yaxis .label .set_color (p2 .get_color ())
1151+ par2 .yaxis .label .set_color (p3 .get_color ())
1152+
1153+ tkw = dict (size = 4 , width = 1.5 )
1154+ host .tick_params (axis = 'y' , colors = p1 .get_color (), ** tkw )
1155+ par1 .tick_params (axis = 'y' , colors = p2 .get_color (), ** tkw )
1156+ par2 .tick_params (axis = 'y' , colors = p3 .get_color (), ** tkw )
1157+ host .tick_params (axis = 'x' , ** tkw )
0 commit comments