@@ -753,6 +753,7 @@ class MPLPlot(object):
753
753
754
754
"""
755
755
_default_rot = 0
756
+ orientation = None
756
757
757
758
_pop_attributes = ['label' , 'style' , 'logy' , 'logx' , 'loglog' ,
758
759
'mark_right' , 'stacked' ]
@@ -788,7 +789,14 @@ def __init__(self, data, kind=None, by=None, subplots=False, sharex=True,
788
789
self .use_index = use_index
789
790
790
791
self .fontsize = fontsize
791
- self .rot = rot
792
+
793
+ if rot is not None :
794
+ self .rot = rot
795
+ else :
796
+ if isinstance (self ._default_rot , dict ):
797
+ self .rot = self ._default_rot [self .kind ]
798
+ else :
799
+ self .rot = self ._default_rot
792
800
793
801
if grid is None :
794
802
grid = False if secondary_y else True
@@ -1018,14 +1026,30 @@ def _adorn_subplots(self):
1018
1026
else :
1019
1027
self .axes [0 ].set_title (self .title )
1020
1028
1021
- if self ._need_to_set_index :
1022
- labels = [com .pprint_thing (key ) for key in self .data .index ]
1023
- labels = dict (zip (range (len (self .data .index )), labels ))
1029
+ labels = [com .pprint_thing (key ) for key in self .data .index ]
1030
+ labels = dict (zip (range (len (self .data .index )), labels ))
1024
1031
1025
- for ax_ in self .axes :
1026
- # ax_.set_xticks(self.xticks)
1027
- xticklabels = [labels .get (x , '' ) for x in ax_ .get_xticks ()]
1028
- ax_ .set_xticklabels (xticklabels , rotation = self .rot )
1032
+ for ax in self .axes :
1033
+ if self .orientation == 'vertical' or self .orientation is None :
1034
+ if self ._need_to_set_index :
1035
+ xticklabels = [labels .get (x , '' ) for x in ax .get_xticks ()]
1036
+ ax .set_xticklabels (xticklabels )
1037
+ self ._apply_axis_properties (ax .xaxis , rot = self .rot ,
1038
+ fontsize = self .fontsize )
1039
+ elif self .orientation == 'horizontal' :
1040
+ if self ._need_to_set_index :
1041
+ yticklabels = [labels .get (y , '' ) for y in ax .get_yticks ()]
1042
+ ax .set_yticklabels (yticklabels )
1043
+ self ._apply_axis_properties (ax .yaxis , rot = self .rot ,
1044
+ fontsize = self .fontsize )
1045
+
1046
+ def _apply_axis_properties (self , axis , rot = None , fontsize = None ):
1047
+ labels = axis .get_majorticklabels () + axis .get_minorticklabels ()
1048
+ for label in labels :
1049
+ if rot is not None :
1050
+ label .set_rotation (rot )
1051
+ if fontsize is not None :
1052
+ label .set_fontsize (fontsize )
1029
1053
1030
1054
@property
1031
1055
def legend_title (self ):
@@ -1336,6 +1360,8 @@ def _get_errorbars(self, label=None, index=None, xerr=True, yerr=True):
1336
1360
1337
1361
1338
1362
class KdePlot (MPLPlot ):
1363
+ orientation = 'vertical'
1364
+
1339
1365
def __init__ (self , data , bw_method = None , ind = None , ** kwargs ):
1340
1366
MPLPlot .__init__ (self , data , ** kwargs )
1341
1367
self .bw_method = bw_method
@@ -1480,6 +1506,9 @@ def _post_plot_logic(self):
1480
1506
1481
1507
class LinePlot (MPLPlot ):
1482
1508
1509
+ _default_rot = 30
1510
+ orientation = 'vertical'
1511
+
1483
1512
def __init__ (self , data , ** kwargs ):
1484
1513
MPLPlot .__init__ (self , data , ** kwargs )
1485
1514
if self .stacked :
@@ -1656,16 +1685,9 @@ def _post_plot_logic(self):
1656
1685
1657
1686
index_name = self ._get_index_name ()
1658
1687
1659
- rot = 30
1660
- if self .rot is not None :
1661
- rot = self .rot
1662
-
1663
1688
for ax in self .axes :
1664
1689
if condition :
1665
- format_date_labels (ax , rot = rot )
1666
- elif self .rot is not None :
1667
- for l in ax .get_xticklabels ():
1668
- l .set_rotation (self .rot )
1690
+ format_date_labels (ax , rot = self .rot )
1669
1691
1670
1692
if index_name is not None :
1671
1693
ax .set_xlabel (index_name )
@@ -1766,9 +1788,6 @@ def __init__(self, data, **kwargs):
1766
1788
self .ax_pos = self .tick_pos - self .tickoffset
1767
1789
1768
1790
def _args_adjust (self ):
1769
- if self .rot is None :
1770
- self .rot = self ._default_rot [self .kind ]
1771
-
1772
1791
if com .is_list_like (self .bottom ):
1773
1792
self .bottom = np .array (self .bottom )
1774
1793
if com .is_list_like (self .left ):
@@ -1858,8 +1877,7 @@ def _post_plot_logic(self):
1858
1877
if self .kind == 'bar' :
1859
1878
ax .set_xlim ((s_edge , e_edge ))
1860
1879
ax .set_xticks (self .tick_pos )
1861
- ax .set_xticklabels (str_index , rotation = self .rot ,
1862
- fontsize = self .fontsize )
1880
+ ax .set_xticklabels (str_index )
1863
1881
if not self .log : # GH3254+
1864
1882
ax .axhline (0 , color = 'k' , linestyle = '--' )
1865
1883
if name is not None :
@@ -1868,14 +1886,22 @@ def _post_plot_logic(self):
1868
1886
# horizontal bars
1869
1887
ax .set_ylim ((s_edge , e_edge ))
1870
1888
ax .set_yticks (self .tick_pos )
1871
- ax .set_yticklabels (str_index , rotation = self .rot ,
1872
- fontsize = self .fontsize )
1889
+ ax .set_yticklabels (str_index )
1873
1890
ax .axvline (0 , color = 'k' , linestyle = '--' )
1874
1891
if name is not None :
1875
1892
ax .set_ylabel (name )
1876
1893
else :
1877
1894
raise NotImplementedError (self .kind )
1878
1895
1896
+ @property
1897
+ def orientation (self ):
1898
+ if self .kind == 'bar' :
1899
+ return 'vertical'
1900
+ elif self .kind == 'barh' :
1901
+ return 'horizontal'
1902
+ else :
1903
+ raise NotImplementedError (self .kind )
1904
+
1879
1905
1880
1906
class PiePlot (MPLPlot ):
1881
1907
0 commit comments