@@ -1425,12 +1425,40 @@ def z_value(ci):
14251425
14261426 xlimlow , xlimhigh = axx .get_xlim ()
14271427
1428+ """
1429+ Function to lighten a colour
1430+ credits to https://gist.github.com/ihincks/6a420b599f43fcd7dbd79d56798c4e5a
1431+ """
1432+ def lighten_color (color , amount = 0.5 ):
1433+ """
1434+ Lightens the given color by multiplying (1-luminosity) by the given amount.
1435+ Input can be matplotlib color string, hex string, or RGB tuple.
1436+
1437+ Examples:
1438+ >> lighten_color('g', 0.3)
1439+ >> lighten_color('#F034A3', 0.6)
1440+ >> lighten_color((.3,.55,.1), 0.5)
1441+ """
1442+ import matplotlib .colors as mc
1443+ import colorsys
1444+ try :
1445+ c = mc .cnames [color ]
1446+ except :
1447+ c = color
1448+ c = colorsys .rgb_to_hls (* mc .to_rgb (c ))
1449+ return colorsys .hls_to_rgb (c [0 ], 1 - amount * (1 - c [1 ]), c [2 ])
1450+
1451+
14281452 if jj == 0 :
1453+
1454+ # colours
1455+ control_color = swarm_colors [0 ]
1456+ test_color = swarm_colors [1 ]
14291457 # Draw stacked bar chart
1430- axx .bar (0 , ref , color = color_col )
1431- axx .bar (effsize_line_start , diff , color = color_col )
1432- axx .bar (0 , 1 - ref , bottom = ref , color = color_col )
1433- axx .bar (effsize_line_start , 1 - diff , bottom = diff , color = color_col )
1458+ axx .bar (0 , ref , width = 0.5 , color = control_color )
1459+ axx .bar (effsize_line_start , diff , width = 0.5 , color = test_color )
1460+ axx .bar (0 , 1 - ref , bottom = ref , width = 0.5 , color = lighten_color ( control_color ))
1461+ axx .bar (effsize_line_start , 1 - diff , bottom = diff , width = 0.5 , color = lighten_color ( test_color ) )
14341462
14351463 # Control group's proportion error
14361464 control_err = z_score * np .sqrt (ref * (1 - ref )/ (counts_lst [0 ]))
0 commit comments