I am building my own legend for a complicated figure where some lines have a hexadecimal color (e.g. #009933). To build the legend I have a column 'color' that has the same hexadecimal color as the line in the plot. I apply the color to the background of the color cell using the pandas apply function, as shown below.
import pandas as pd
def legend_styling(val):
if val.name == 'color':
return ['background-color: %s'%x for x in val]
elif val.name == 'shift':
return ['font-weight: bold' for x in val]
df = pd.DataFrame({
'form': {1: 'C4H6O5', 2: 'C4H6O5', 3: 'C4H4O4', 4: 'C4H5N3O'},
'name': {1: 'Malate', 2: '3-Dehydro-L-threonate', 3: 'Fumarate', 4: 'Cytosine'},
'color': {1: '#009933', 2: '#009933', 3: '#e67300', 4: '#e63900'},
'shift': {1: 'm+0', 2: 'm+0', 3: 'm+0', 4: 'm+0'}
})
df.style.apply(legend_styling, axis=0,subset=['color','shift'])
I would like to color the text (the black hex codes) in the 'color' column the same as the background so that they blend away. I somehow need to apply both of the following CSS styling options to the cell 'background-color: #xxxxxx' and 'color: #xxxxxx'. Is there a way of doing this?
