@@ -3250,6 +3250,43 @@ def test_plot_no_numeric_data(self):
3250
3250
with pytest .raises (TypeError ):
3251
3251
df .plot ()
3252
3252
3253
+ @pytest .mark .slow
3254
+ @pytest .mark .parametrize ('method' , ['bar' , 'barh' ])
3255
+ def test_bar_ticklabel_consistence (self , method ):
3256
+ # Draw two consecutiv bar plot with consistent ticklabels
3257
+ # GH: 26186
3258
+ def get_main_axis (ax ):
3259
+ if method == 'barh' :
3260
+ return ax .yaxis
3261
+ elif method == 'bar' :
3262
+ return ax .xaxis
3263
+ data = {"A" : 0 , "B" : 3 , "C" : - 4 }
3264
+ df = pd .DataFrame .from_dict (data , orient = "index" , columns = ["Value" ])
3265
+ ax = getattr (df .plot , method )()
3266
+ ax .get_figure ().canvas .draw ()
3267
+ xticklabels = [t .get_text ()
3268
+ for t in get_main_axis (ax ).get_ticklabels ()]
3269
+ label_positions_1 = dict (zip (xticklabels ,
3270
+ get_main_axis (ax ).get_ticklocs ()))
3271
+ df = df .sort_values ("Value" ) * - 2
3272
+ ax = getattr (df .plot , method )(ax = ax , color = "red" )
3273
+ ax .get_figure ().canvas .draw ()
3274
+ xticklabels = [t .get_text ()
3275
+ for t in get_main_axis (ax ).get_ticklabels ()]
3276
+ label_positions_2 = dict (zip (xticklabels ,
3277
+ get_main_axis (ax ).get_ticklocs ()))
3278
+ assert label_positions_1 == label_positions_2
3279
+
3280
+ def test_bar_numeric (self ):
3281
+ # Bar plot with numeric index have tick location values equal to index
3282
+ # values
3283
+ # GH: 11465
3284
+ index = np .arange (10 , 20 )
3285
+ df = pd .DataFrame (np .random .rand (10 ), index = np .arange (10 , 20 ))
3286
+ ax = df .plot .bar ()
3287
+ ticklocs = ax .xaxis .get_ticklocs ()
3288
+ tm .assert_numpy_array_equal (ticklocs , index )
3289
+
3253
3290
3254
3291
def _generate_4_axes_via_gridspec ():
3255
3292
import matplotlib .pyplot as plt
0 commit comments