@@ -770,6 +770,64 @@ def plotf(ax, x, y, style=None, **kwds):
770
770
771
771
return plotf
772
772
773
+
774
+ def _lineplot_plotf (f , stacked , subplots ):
775
+ def plotf (ax , x , y , style = None , column_num = None , ** kwds ):
776
+ # column_num is used to get the target column from protf in line and area plots
777
+ if not hasattr (ax , '_pos_prior' ) or column_num == 0 :
778
+ LinePlot ._initialize_prior (ax , len (y ))
779
+ y_values = LinePlot ._get_stacked_values (ax , y , kwds ['label' ], stacked )
780
+ lines = f (ax , x , y_values , style = style , ** kwds )
781
+ LinePlot ._update_prior (ax , y , stacked , subplots )
782
+ return lines
783
+
784
+ return plotf
785
+
786
+
787
+ def _areaplot_plotf (f , stacked , subplots ):
788
+ import matplotlib .pyplot as plt
789
+ def plotf (ax , x , y , style = None , column_num = None , ** kwds ):
790
+ if not hasattr (ax , '_pos_prior' ) or column_num == 0 :
791
+ LinePlot ._initialize_prior (ax , len (y ))
792
+ y_values = LinePlot ._get_stacked_values (ax , y , kwds ['label' ], stacked )
793
+ lines = f (ax , x , y_values , style = style , ** kwds )
794
+
795
+ # get data from the line to get coordinates for fill_between
796
+ xdata , y_values = lines [0 ].get_data (orig = False )
797
+
798
+ if (y >= 0 ).all ():
799
+ start = ax ._pos_prior
800
+ elif (y <= 0 ).all ():
801
+ start = ax ._neg_prior
802
+ else :
803
+ start = np .zeros (len (y ))
804
+
805
+ if not 'color' in kwds :
806
+ kwds ['color' ] = lines [0 ].get_color ()
807
+
808
+ plt .Axes .fill_between (ax , xdata , start , y_values , ** kwds )
809
+ LinePlot ._update_prior (ax , y , stacked , subplots )
810
+ return lines
811
+
812
+ return plotf
813
+
814
+
815
+ def _histplot_plotf (bins , bottom , stacked , subplots ):
816
+ import matplotlib .pyplot as plt
817
+ def plotf (ax , y , style = None , column_num = None , ** kwds ):
818
+ if not hasattr (ax , '_pos_prior' ) or column_num == 0 :
819
+ LinePlot ._initialize_prior (ax , len (bins ) - 1 )
820
+ y = y [~ com .isnull (y )]
821
+ new_bottom = ax ._pos_prior + bottom
822
+ # ignore style
823
+ n , new_bins , patches = plt .Axes .hist (ax , y , bins = bins ,
824
+ bottom = new_bottom , ** kwds )
825
+ LinePlot ._update_prior (ax , n , stacked , subplots )
826
+ return patches
827
+
828
+ return plotf
829
+
830
+
773
831
class MPLPlot (object ):
774
832
"""
775
833
Base class for assembling a pandas plot using matplotlib
@@ -1640,17 +1698,8 @@ def _get_stacked_values(cls, ax, y, label, stacked):
1640
1698
1641
1699
def _get_plot_function (self ):
1642
1700
f = MPLPlot ._get_plot_function (self )
1643
- stacked = self .stacked
1644
- subplots = self .subplots
1645
- def plotf (ax , x , y , style = None , column_num = None , ** kwds ):
1646
- # column_num is used to get the target column from protf in line and area plots
1647
- if not hasattr (ax , '_pos_prior' ) or column_num == 0 :
1648
- LinePlot ._initialize_prior (ax , len (y ))
1649
- y_values = LinePlot ._get_stacked_values (ax , y , kwds ['label' ], stacked )
1650
- lines = f (ax , x , y_values , style = style , ** kwds )
1651
- LinePlot ._update_prior (ax , y , stacked , subplots )
1652
- return lines
1653
- return plotf
1701
+
1702
+ return _lineplot_plotf (f , self .stacked , self .subplots )
1654
1703
1655
1704
def _get_ts_plot_function (self ):
1656
1705
from pandas .tseries .plotting import tsplot
@@ -1739,35 +1788,12 @@ def __init__(self, data, **kwargs):
1739
1788
self .kwds .setdefault ('alpha' , 0.5 )
1740
1789
1741
1790
def _get_plot_function (self ):
1742
- import matplotlib .pyplot as plt
1743
1791
if self .logy or self .loglog :
1744
1792
raise ValueError ("Log-y scales are not supported in area plot" )
1745
1793
else :
1746
1794
f = MPLPlot ._get_plot_function (self )
1747
- stacked = self .stacked
1748
- subplots = self .subplots
1749
- def plotf (ax , x , y , style = None , column_num = None , ** kwds ):
1750
- if not hasattr (ax , '_pos_prior' ) or column_num == 0 :
1751
- LinePlot ._initialize_prior (ax , len (y ))
1752
- y_values = LinePlot ._get_stacked_values (ax , y , kwds ['label' ], stacked )
1753
- lines = f (ax , x , y_values , style = style , ** kwds )
1754
-
1755
- # get data from the line to get coordinates for fill_between
1756
- xdata , y_values = lines [0 ].get_data (orig = False )
1757
-
1758
- if (y >= 0 ).all ():
1759
- start = ax ._pos_prior
1760
- elif (y <= 0 ).all ():
1761
- start = ax ._neg_prior
1762
- else :
1763
- start = np .zeros (len (y ))
1764
-
1765
- if not 'color' in kwds :
1766
- kwds ['color' ] = lines [0 ].get_color ()
1767
1795
1768
- plt .Axes .fill_between (ax , xdata , start , y_values , ** kwds )
1769
- LinePlot ._update_prior (ax , y , stacked , subplots )
1770
- return lines
1796
+ return _areaplot_plotf (f , self .stacked , self .subplots )
1771
1797
1772
1798
return plotf
1773
1799
@@ -1957,22 +1983,7 @@ def _args_adjust(self):
1957
1983
self .bottom = np .array (self .bottom )
1958
1984
1959
1985
def _get_plot_function (self ):
1960
- import matplotlib .pyplot as plt
1961
- bins = self .bins
1962
- bottom = self .bottom
1963
- stacked = self .stacked
1964
- subplots = self .subplots
1965
- def plotf (ax , y , style = None , column_num = None , ** kwds ):
1966
- if not hasattr (ax , '_pos_prior' ) or column_num == 0 :
1967
- LinePlot ._initialize_prior (ax , len (self .bins ) - 1 )
1968
- y = y [~ com .isnull (y )]
1969
- new_bottom = ax ._pos_prior + bottom
1970
- # ignore style
1971
- n , new_bins , patches = plt .Axes .hist (ax , y , bins = bins ,
1972
- bottom = new_bottom , ** kwds )
1973
- LinePlot ._update_prior (ax , n , stacked , subplots )
1974
- return patches
1975
- return plotf
1986
+ return _histplot_plotf (self .bins , self .bottom , self .stacked , self .subplots )
1976
1987
1977
1988
def _make_plot (self ):
1978
1989
plotf = self ._get_plot_function ()
0 commit comments