19
19
20
20
from pandas .types .common import is_float , is_string_like , is_list_like
21
21
22
- import warnings
23
-
24
22
import numpy as np
25
23
import pandas as pd
26
24
from pandas .compat import range
@@ -848,14 +846,20 @@ def set_properties(self, subset=None, **kwargs):
848
846
return self .applymap (f , subset = subset )
849
847
850
848
@staticmethod
851
- def _bar_left (s , color , width ):
849
+ def _bar_left (s , color , width , base ):
852
850
"""
853
851
The minimum value is aligned at the left of the cell
854
852
.. versionadded:: 0.17.1
855
853
856
854
Parameters
857
855
----------
858
856
color: 2-tuple/list, of [``color_negative``, ``color_positive``]
857
+ width: float
858
+ A number between 0 or 100. The largest value will cover ``width``
859
+ percent of the cell's width
860
+ base: str
861
+ The base css format of the cell, e.g.:
862
+ ``base = 'width: 10em; height: 80%;'``
859
863
860
864
Returns
861
865
-------
@@ -873,14 +877,20 @@ def _bar_left(s, color, width):
873
877
else base for x in normed ]
874
878
875
879
@staticmethod
876
- def _bar_center_zero (s , color , width ):
880
+ def _bar_center_zero (s , color , width , base ):
877
881
"""
878
882
Creates a bar chart where the zero is centered in the cell
879
883
.. versionadded:: 0.19.2
880
884
881
885
Parameters
882
886
----------
883
887
color: 2-tuple/list, of [``color_negative``, ``color_positive``]
888
+ width: float
889
+ A number between 0 or 100. The largest value will cover ``width``
890
+ percent of the cell's width
891
+ base: str
892
+ The base css format of the cell, e.g.:
893
+ ``base = 'width: 10em; height: 80%;'``
884
894
885
895
Returns
886
896
-------
@@ -893,8 +903,6 @@ def _bar_center_zero(s, color, width):
893
903
894
904
normed = s * 50 * width / (100 * m )
895
905
896
- base = 'width: 10em; height: 80%;'
897
-
898
906
attrs_neg = (base + 'background: linear-gradient(90deg, transparent 0%'
899
907
', transparent {w}%, {c} {w}%, '
900
908
'{c} 50%, transparent 50%)' )
@@ -908,14 +916,20 @@ def _bar_center_zero(s, color, width):
908
916
for x in normed ]
909
917
910
918
@staticmethod
911
- def _bar_center_mid (s , color , width ):
919
+ def _bar_center_mid (s , color , width , base ):
912
920
"""
913
921
Creates a bar chart where the midpoint is centered in the cell
914
922
.. versionadded:: 0.19.2
915
923
916
924
Parameters
917
925
----------
918
926
color: 2-tuple/list, of [``color_negative``, ``color_positive``]
927
+ width: float
928
+ A number between 0 or 100. The largest value will cover ``width``
929
+ percent of the cell's width
930
+ base: str
931
+ The base css format of the cell, e.g.:
932
+ ``base = 'width: 10em; height: 80%;'``
919
933
920
934
Returns
921
935
-------
@@ -938,8 +952,6 @@ def _bar_center_mid(s, color, width):
938
952
939
953
normed = zero + slope * s
940
954
941
- base = 'width: 10em; height: 80%;'
942
-
943
955
attrs_neg = (base + 'background: linear-gradient(90deg, transparent 0%'
944
956
', transparent {w}%, {c} {w}%, '
945
957
'{c} {zero}%, transparent {zero}%)' )
@@ -987,27 +999,27 @@ def bar(self, subset=None, align='left', axis=0,
987
999
subset = _maybe_numeric_slice (self .data , subset )
988
1000
subset = _non_reducing_slice (subset )
989
1001
1002
+ base = 'width: 10em; height: 80%;'
1003
+
990
1004
if not (is_list_like (color )):
991
1005
color = [color , color ]
992
1006
elif len (color ) == 1 :
993
1007
color = [color [0 ], color [0 ]]
994
1008
elif len (color ) > 2 :
995
1009
msg = ("Must pass `color` as string or a list-like"
996
- " of length 2 [ `color_negative`, `color_positive`] "
997
- "(eg: color=['#d65f5f', '#5fba7d'])\n "
998
- "Only the first two list elements will be used here." )
999
- warnings .warn (msg , UserWarning )
1000
- color = [color [0 ], color [1 ]]
1010
+ " of length 2: [`color_negative`, `color_positive`]\n "
1011
+ "(eg: color=['#d65f5f', '#5fba7d'])" )
1012
+ raise ValueError (msg )
1001
1013
1002
1014
if align == 'left' :
1003
1015
self .apply (self ._bar_left , subset = subset , axis = axis , color = color ,
1004
- width = width )
1016
+ width = width , base = base )
1005
1017
elif align == 'zero' :
1006
1018
self .apply (self ._bar_center_zero , subset = subset , axis = axis ,
1007
- color = color , width = width )
1019
+ color = color , width = width , base = base )
1008
1020
elif align == 'mid' :
1009
1021
self .apply (self ._bar_center_mid , subset = subset , axis = axis ,
1010
- color = color , width = width )
1022
+ color = color , width = width , base = base )
1011
1023
return self
1012
1024
1013
1025
def highlight_max (self , subset = None , color = 'yellow' , axis = 0 ):
0 commit comments