def relative_luminance(color):
 rgb = mpl.colors.colorConverter.to_rgba_array(color)[:, :3]
 rgb = np.where((rgb <= 0.03928), (rgb / 12.92), (((rgb + 0.055) / 1.055) ** 2.4))
 lum = rgb.dot([0.2126, 0.7152, 0.0722])
 try:
  return lum.item()
 except ValueError:
  return lum

def relative_luminance ( color ) : rgb = mpl . colors . colorConverter . to_rgba_array ( color ) [ : , : 3 ] rgb = np . where ( ( rgb <= 0.03928 ) , ( rgb / 12.92 ) , ( ( ( rgb + 0.055 ) / 1.055 ) ** 2.4 ) ) lum = rgb . dot ( [ 0.2126 , 0.7152 , 0.0722 ] ) try : return lum . item ( ) except ValueError : return lum
calculate the relative luminance of a color according to w3c standards parameters color : matplotlib color or sequence of matplotlib colors hex code .