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
@@ -859,14 +857,20 @@ def set_properties(self, subset=None, **kwargs):
859
857
return self .applymap (f , subset = subset )
860
858
861
859
@staticmethod
862
- def _bar_left (s , color , width ):
860
+ def _bar_left (s , color , width , base ):
863
861
"""
864
862
The minimum value is aligned at the left of the cell
865
863
.. versionadded:: 0.17.1
866
864
867
865
Parameters
868
866
----------
869
867
color: 2-tuple/list, of [``color_negative``, ``color_positive``]
868
+ width: float
869
+ A number between 0 or 100. The largest value will cover ``width``
870
+ percent of the cell's width
871
+ base: str
872
+ The base css format of the cell, e.g.:
873
+ ``base = 'width: 10em; height: 80%;'``
870
874
871
875
Returns
872
876
-------
@@ -884,14 +888,20 @@ def _bar_left(s, color, width):
884
888
else base for x in normed ]
885
889
886
890
@staticmethod
887
- def _bar_center_zero (s , color , width ):
891
+ def _bar_center_zero (s , color , width , base ):
888
892
"""
889
893
Creates a bar chart where the zero is centered in the cell
890
894
.. versionadded:: 0.19.2
891
895
892
896
Parameters
893
897
----------
894
898
color: 2-tuple/list, of [``color_negative``, ``color_positive``]
899
+ width: float
900
+ A number between 0 or 100. The largest value will cover ``width``
901
+ percent of the cell's width
902
+ base: str
903
+ The base css format of the cell, e.g.:
904
+ ``base = 'width: 10em; height: 80%;'``
895
905
896
906
Returns
897
907
-------
@@ -904,8 +914,6 @@ def _bar_center_zero(s, color, width):
904
914
905
915
normed = s * 50 * width / (100 * m )
906
916
907
- base = 'width: 10em; height: 80%;'
908
-
909
917
attrs_neg = (base + 'background: linear-gradient(90deg, transparent 0%'
910
918
', transparent {w}%, {c} {w}%, '
911
919
'{c} 50%, transparent 50%)' )
@@ -919,14 +927,20 @@ def _bar_center_zero(s, color, width):
919
927
for x in normed ]
920
928
921
929
@staticmethod
922
- def _bar_center_mid (s , color , width ):
930
+ def _bar_center_mid (s , color , width , base ):
923
931
"""
924
932
Creates a bar chart where the midpoint is centered in the cell
925
933
.. versionadded:: 0.19.2
926
934
927
935
Parameters
928
936
----------
929
937
color: 2-tuple/list, of [``color_negative``, ``color_positive``]
938
+ width: float
939
+ A number between 0 or 100. The largest value will cover ``width``
940
+ percent of the cell's width
941
+ base: str
942
+ The base css format of the cell, e.g.:
943
+ ``base = 'width: 10em; height: 80%;'``
930
944
931
945
Returns
932
946
-------
@@ -949,8 +963,6 @@ def _bar_center_mid(s, color, width):
949
963
950
964
normed = zero + slope * s
951
965
952
- base = 'width: 10em; height: 80%;'
953
-
954
966
attrs_neg = (base + 'background: linear-gradient(90deg, transparent 0%'
955
967
', transparent {w}%, {c} {w}%, '
956
968
'{c} {zero}%, transparent {zero}%)' )
@@ -998,27 +1010,27 @@ def bar(self, subset=None, align='left', axis=0,
998
1010
subset = _maybe_numeric_slice (self .data , subset )
999
1011
subset = _non_reducing_slice (subset )
1000
1012
1013
+ base = 'width: 10em; height: 80%;'
1014
+
1001
1015
if not (is_list_like (color )):
1002
1016
color = [color , color ]
1003
1017
elif len (color ) == 1 :
1004
1018
color = [color [0 ], color [0 ]]
1005
1019
elif len (color ) > 2 :
1006
1020
msg = ("Must pass `color` as string or a list-like"
1007
- " of length 2 [ `color_negative`, `color_positive`] "
1008
- "(eg: color=['#d65f5f', '#5fba7d'])\n "
1009
- "Only the first two list elements will be used here." )
1010
- warnings .warn (msg , UserWarning )
1011
- color = [color [0 ], color [1 ]]
1021
+ " of length 2: [`color_negative`, `color_positive`]\n "
1022
+ "(eg: color=['#d65f5f', '#5fba7d'])" )
1023
+ raise ValueError (msg )
1012
1024
1013
1025
if align == 'left' :
1014
1026
self .apply (self ._bar_left , subset = subset , axis = axis , color = color ,
1015
- width = width )
1027
+ width = width , base = base )
1016
1028
elif align == 'zero' :
1017
1029
self .apply (self ._bar_center_zero , subset = subset , axis = axis ,
1018
- color = color , width = width )
1030
+ color = color , width = width , base = base )
1019
1031
elif align == 'mid' :
1020
1032
self .apply (self ._bar_center_mid , subset = subset , axis = axis ,
1021
- color = color , width = width )
1033
+ color = color , width = width , base = base )
1022
1034
return self
1023
1035
1024
1036
def highlight_max (self , subset = None , color = 'yellow' , axis = 0 ):
0 commit comments