'How to match the kdeplot hue with scatter plot hue with different groups?
JMP image of what I am trying to recreate in python
I would like to group the color of the kde plot and scatter plot in my function but cannot figure out how to make the palettes match. Below is the function where i try to use cmap, and what I currently get back.
def plot_wat_specs2(spec_list,data,x,y,hue=None,kde_hue=None):
fig,ax= plt.subplots(figsize = (7,7))
ax= sns.scatterplot(data=data, x=x, y=y, ax = ax,hue=hue,cmap = 'Accent' )
ax.legend(loc='center right',bbox_to_anchor=(1.5,0.5))
ax.invert_yaxis()
if kde_hue is not None:
for split in list(data[kde_hue].unique()):
data2=data[data['SPLIT']==split]
if len(data2)>2 :
ax= sns.kdeplot(data=data2, x=x, y=y, ax = ax,levels=[0.5],cmap = 'Accent')
else:
ax=sns.kdeplot(data=wat_data_agg[wat_data_agg['SPLIT']=='TT'], x=x, y=y, ax = ax,levels=[0.5] ,cmap = 'Accent')
ax.axvline(x=spec_list[spec_list['PARAMETER']==x].LSL.values[0],color='r')
ax.axvline(x=spec_list[spec_list['PARAMETER']==x].USL.values[0],color='r')
ax.axvline(x=spec_list[spec_list['PARAMETER']==x].TARGET.values[0],color='g')
ax.axhline(y=spec_list[spec_list['PARAMETER']==y].LSL.values[0],color='r')
ax.axhline(y=spec_list[spec_list['PARAMETER']==y].USL.values[0],color='r')
ax.axhline(y=spec_list[spec_list['PARAMETER']==y].TARGET.values[0],color='g')
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
