I would be grateful if you could give me your advice on the code sample below. I am trying to get all the values in the Graphidx or Graphidx with a value of 1 to display all values (no hue) and all values with 2 to display a hue based on the Urg column. I wrote a small wrapper function called myboxplot but I cannot get the variable mycol to invoke the logic. My question to you all is
- How can I invoke the logic in my code sample myboxplot
- I have used kwargs[‘data’] to look at the data. How can I use kwargs to retrieve column headers, values etc. Can you please give me the exact syntax that I would use to retrieve these.
I am perhaps missing a simple trick here and I know that I could use pd.concat to append the same data and display All ,U and NU as three graphs. If you can provide some help and insight into my questions above I would be extremely grateful.
Many Thanks
import pandas as pd
import seaborn as sns
d= {
'spec':['A','A','A','A','A','A','B','B','B','B','B','B'],
'wait':[10,20,30,40,50,60,100,120,140,160,180,200],
'Graphidx':[1,1,1,2,2,2,1,1,1,2,2,2],
'Graphidx1':[1,1,1,2,2,2,1,1,1,2,2,2],
'Urg':['U','U','NU','U','U','NU','U','U','NU','U','U','NU']
}
mydf = pd.DataFrame(d)
print(mydf)
print(mydf.dtypes)
def myboxplot(x,y,myhue,mycol,**kwargs):
print('x',x)
print('y',y)
print('myhue',myhue)
print('mycol',mycol)
print('kwargs[data]',kwargs['data'])
if mycol == 1:
print('1 Triggered')
sns.boxplot(x=x,y=y,**kwargs)
elif mycol == 2:
print('2 Triggered')
sns.boxplot(x=x,y=y,hue=myhue,**kwargs)
g2 = sns.FacetGrid(mydf,height=5,col='Graphidx',col_wrap=2,sharey=False,sharex=False)
myboxplot1 = g2.map_dataframe(myboxplot,x='wait',y='spec',mycol='Graphidx1',myhue='Urg')