@@ -1090,3 +1090,50 @@ def test_mixed_collection():
1090
1090
1091
1091
ax .set_xlim (0 , 16 )
1092
1092
ax .set_ylim (0 , 16 )
1093
+
1094
+
1095
+ @image_comparison (baseline_images = ['twin_spines' ], remove_text = True ,
1096
+ extensions = ['png' ])
1097
+ def test_twin_spines ():
1098
+
1099
+ def make_patch_spines_invisible (ax ):
1100
+ ax .set_frame_on (True )
1101
+ ax .patch .set_visible (False )
1102
+ for sp in ax .spines .itervalues ():
1103
+ sp .set_visible (False )
1104
+
1105
+ fig = plt .figure (figsize = (4 , 3 ))
1106
+ fig .subplots_adjust (right = 0.75 )
1107
+
1108
+ host = fig .add_subplot (111 )
1109
+ par1 = host .twinx ()
1110
+ par2 = host .twinx ()
1111
+
1112
+ # Offset the right spine of par2. The ticks and label have already been
1113
+ # placed on the right by twinx above.
1114
+ par2 .spines ["right" ].set_position (("axes" , 1.2 ))
1115
+ # Having been created by twinx, par2 has its frame off, so the line of its
1116
+ # detached spine is invisible. First, activate the frame but make the patch
1117
+ # and spines invisible.
1118
+ make_patch_spines_invisible (par2 )
1119
+ # Second, show the right spine.
1120
+ par2 .spines ["right" ].set_visible (True )
1121
+
1122
+ p1 , = host .plot ([0 , 1 , 2 ], [0 , 1 , 2 ], "b-" )
1123
+ p2 , = par1 .plot ([0 , 1 , 2 ], [0 , 3 , 2 ], "r-" )
1124
+ p3 , = par2 .plot ([0 , 1 , 2 ], [50 , 30 , 15 ], "g-" )
1125
+
1126
+ host .set_xlim (0 , 2 )
1127
+ host .set_ylim (0 , 2 )
1128
+ par1 .set_ylim (0 , 4 )
1129
+ par2 .set_ylim (1 , 65 )
1130
+
1131
+ host .yaxis .label .set_color (p1 .get_color ())
1132
+ par1 .yaxis .label .set_color (p2 .get_color ())
1133
+ par2 .yaxis .label .set_color (p3 .get_color ())
1134
+
1135
+ tkw = dict (size = 4 , width = 1.5 )
1136
+ host .tick_params (axis = 'y' , colors = p1 .get_color (), ** tkw )
1137
+ par1 .tick_params (axis = 'y' , colors = p2 .get_color (), ** tkw )
1138
+ par2 .tick_params (axis = 'y' , colors = p3 .get_color (), ** tkw )
1139
+ host .tick_params (axis = 'x' , ** tkw )
0 commit comments