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