@@ -2997,9 +2997,8 @@ def test_secondary_axis_font_size(self, method):
2997
2997
2998
2998
@pytest .mark .slow
2999
2999
def test_x_string_values_ticks (self ):
3000
- # GH: 7612
3001
- # GH: 22334
3002
- # GH: 15912
3000
+ # Test if string plot index have a fixed xtick position
3001
+ # GH: 7612, GH: 22334
3003
3002
df = pd .DataFrame ({'sales' : [3 , 2 , 3 ],
3004
3003
'visits' : [20 , 42 , 28 ],
3005
3004
'day' : ['Monday' , 'Tuesday' , 'Wednesday' ]})
@@ -3012,6 +3011,24 @@ def test_x_string_values_ticks(self):
3012
3011
assert labels_position ['Tuesday' ] == 1.0
3013
3012
assert labels_position ['Wednesday' ] == 2.0
3014
3013
3014
+ @pytest .mark .slow
3015
+ def test_x_multiindex_values_ticks (self ):
3016
+ # Test if multiindex plot index have a fixed xtick position
3017
+ # GH: 15912
3018
+ index = pd .MultiIndex .from_product ([[2012 , 2013 ], [1 , 2 ]])
3019
+ df = pd .DataFrame (np .random .randn (4 , 2 ),
3020
+ columns = ['A' , 'B' ],
3021
+ index = index )
3022
+ ax = df .plot ()
3023
+ ax .set_xlim (- 1 , 4 )
3024
+ xticklabels = [t .get_text () for t in ax .get_xticklabels ()]
3025
+ labels_position = dict (zip (xticklabels , ax .get_xticks ()))
3026
+ # Testing if the label stayed at the right position
3027
+ assert labels_position ['(2012, 1)' ] == 0.0
3028
+ assert labels_position ['(2012, 2)' ] == 1.0
3029
+ assert labels_position ['(2013, 1)' ] == 2.0
3030
+ assert labels_position ['(2013, 2)' ] == 3.0
3031
+
3015
3032
3016
3033
def _generate_4_axes_via_gridspec ():
3017
3034
import matplotlib .pyplot as plt
0 commit comments