@@ -1084,14 +1084,17 @@ def test_bar_categorical(self):
1084
1084
for df in [df1 , df2 ]:
1085
1085
ax = df .plot .bar ()
1086
1086
ticks = ax .xaxis .get_ticklocs ()
1087
- tm .assert_numpy_array_equal (ticks , np .array ([0 , 1 , 2 , 3 , 4 , 5 ]))
1087
+ tm .assert_numpy_array_equal (ticks , np .array ([0 , 1 , 2 , 3 , 4 , 5 ],
1088
+ dtype = np .float ))
1088
1089
assert ax .get_xlim () == (- 0.5 , 5.5 )
1089
1090
# check left-edge of bars
1090
1091
assert ax .patches [0 ].get_x () == - 0.25
1091
1092
assert ax .patches [- 1 ].get_x () == 5.15
1092
1093
1093
1094
ax = df .plot .bar (stacked = True )
1094
- tm .assert_numpy_array_equal (ticks , np .array ([0 , 1 , 2 , 3 , 4 , 5 ]))
1095
+ ticks = ax .xaxis .get_ticklocs ()
1096
+ tm .assert_numpy_array_equal (ticks , np .array ([0 , 1 , 2 , 3 , 4 , 5 ],
1097
+ dtype = np .float ))
1095
1098
assert ax .get_xlim () == (- 0.5 , 5.5 )
1096
1099
assert ax .patches [0 ].get_x () == - 0.25
1097
1100
assert ax .patches [- 1 ].get_x () == 4.75
@@ -3028,6 +3031,43 @@ def test_x_multiindex_values_ticks(self):
3028
3031
assert labels_position ['(2013, 1)' ] == 2.0
3029
3032
assert labels_position ['(2013, 2)' ] == 3.0
3030
3033
3034
+ @pytest .mark .slow
3035
+ @pytest .mark .parametrize ('method' , ['bar' , 'barh' ])
3036
+ def test_bar_ticklabel_consistence (self , method ):
3037
+ # Draw two consecutiv bar plot with consistent ticklabels
3038
+ # GH: 26186
3039
+ def get_main_axis (ax ):
3040
+ if method == 'barh' :
3041
+ return ax .yaxis
3042
+ elif method == 'bar' :
3043
+ return ax .xaxis
3044
+ data = {"A" : 0 , "B" : 3 , "C" : - 4 }
3045
+ df = pd .DataFrame .from_dict (data , orient = "index" , columns = ["Value" ])
3046
+ ax = getattr (df .plot , method )()
3047
+ ax .get_figure ().canvas .draw ()
3048
+ xticklabels = [t .get_text ()
3049
+ for t in get_main_axis (ax ).get_ticklabels ()]
3050
+ label_positions_1 = dict (zip (xticklabels ,
3051
+ get_main_axis (ax ).get_ticklocs ()))
3052
+ df = df .sort_values ("Value" ) * - 2
3053
+ ax = getattr (df .plot , method )(ax = ax , color = "red" )
3054
+ ax .get_figure ().canvas .draw ()
3055
+ xticklabels = [t .get_text ()
3056
+ for t in get_main_axis (ax ).get_ticklabels ()]
3057
+ label_positions_2 = dict (zip (xticklabels ,
3058
+ get_main_axis (ax ).get_ticklocs ()))
3059
+ assert label_positions_1 == label_positions_2
3060
+
3061
+ def test_bar_numeric (self ):
3062
+ # Bar plot with numeric index have tick location values equal to index
3063
+ # values
3064
+ # GH: 11465
3065
+ index = np .arange (10 , 20 )
3066
+ df = pd .DataFrame (np .random .rand (10 ), index = np .arange (10 , 20 ))
3067
+ ax = df .plot .bar ()
3068
+ ticklocs = ax .xaxis .get_ticklocs ()
3069
+ tm .assert_numpy_array_equal (ticklocs , index )
3070
+
3031
3071
3032
3072
def _generate_4_axes_via_gridspec ():
3033
3073
import matplotlib .pyplot as plt
0 commit comments