@@ -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 :
@@ -1657,16 +1686,9 @@ def _post_plot_logic(self):
1657
1686
1658
1687
index_name = self ._get_index_name ()
1659
1688
1660
- rot = 30
1661
- if self .rot is not None :
1662
- rot = self .rot
1663
-
1664
1689
for ax in self .axes :
1665
1690
if condition :
1666
- format_date_labels (ax , rot = rot )
1667
- elif self .rot is not None :
1668
- for l in ax .get_xticklabels ():
1669
- l .set_rotation (self .rot )
1691
+ format_date_labels (ax , rot = self .rot )
1670
1692
1671
1693
if index_name is not None :
1672
1694
ax .set_xlabel (index_name )
@@ -1767,9 +1789,6 @@ def __init__(self, data, **kwargs):
1767
1789
self .ax_pos = self .tick_pos - self .tickoffset
1768
1790
1769
1791
def _args_adjust (self ):
1770
- if self .rot is None :
1771
- self .rot = self ._default_rot [self .kind ]
1772
-
1773
1792
if com .is_list_like (self .bottom ):
1774
1793
self .bottom = np .array (self .bottom )
1775
1794
if com .is_list_like (self .left ):
@@ -1859,8 +1878,7 @@ def _post_plot_logic(self):
1859
1878
if self .kind == 'bar' :
1860
1879
ax .set_xlim ((s_edge , e_edge ))
1861
1880
ax .set_xticks (self .tick_pos )
1862
- ax .set_xticklabels (str_index , rotation = self .rot ,
1863
- fontsize = self .fontsize )
1881
+ ax .set_xticklabels (str_index )
1864
1882
if not self .log : # GH3254+
1865
1883
ax .axhline (0 , color = 'k' , linestyle = '--' )
1866
1884
if name is not None :
@@ -1869,14 +1887,22 @@ def _post_plot_logic(self):
1869
1887
# horizontal bars
1870
1888
ax .set_ylim ((s_edge , e_edge ))
1871
1889
ax .set_yticks (self .tick_pos )
1872
- ax .set_yticklabels (str_index , rotation = self .rot ,
1873
- fontsize = self .fontsize )
1890
+ ax .set_yticklabels (str_index )
1874
1891
ax .axvline (0 , color = 'k' , linestyle = '--' )
1875
1892
if name is not None :
1876
1893
ax .set_ylabel (name )
1877
1894
else :
1878
1895
raise NotImplementedError (self .kind )
1879
1896
1897
+ @property
1898
+ def orientation (self ):
1899
+ if self .kind == 'bar' :
1900
+ return 'vertical'
1901
+ elif self .kind == 'barh' :
1902
+ return 'horizontal'
1903
+ else :
1904
+ raise NotImplementedError (self .kind )
1905
+
1880
1906
1881
1907
class PiePlot (MPLPlot ):
1882
1908
0 commit comments