1

I am trying to color specific points on the seaborn:stripplot based on a defined value. For example,

value=(df['x']=0.0

I know you can do this with regplot, etc using:

df['color']= np.where( value==True , "#9b59b6") and the scatter_kws={'facecolors':df['color']}

Is there a way to do it for the pair grid and stripplot? Specifically, to color a specified value in t1 or t2 below?

I have also tried passing the match var in hue. However, this produced image #2 below and is not what I am looking for.

Here is the df:

par        t1         t2    found   
30000.0   0.50       0.45     yes   
10000.0   0.30       0.12     yes   
3000.0    0.40       0.00     no    

Here is my code:

# Import dependencies
import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt

df = pd.read_csv("data.csv")

# Make the PairGrid
g = sns.PairGrid(df.sort_values("par", ascending=True),
                 x_vars=df.columns[1:3], y_vars=["par"], 
                 height=5, aspect=.65)

# Draw a dot plot using the stripplot function
g.map(sns.stripplot, size=16, orient="h", 
      linewidth=1, edgecolor="gray", palette="ch:2.5,-.2,dark=.3")

sns.set_style("darkgrid")

# Use the same x axis limits on all columns and add better labels
g.set(xlim=(-0.1, 1.1), xlabel="% AF", ylabel="")

# Use semantically meaningful titles for the columns
titles = ["Test 1", "Test 2"]

for ax, title in zip(g.axes.flat, titles):

    # Set a different title for each axes
    ax.set(title=title)

    # Make the grid horizontal instead of vertical
    ax.xaxis.grid(False)
    ax.yaxis.grid(True)

sns.despine(left=True, bottom=True)

I am trying to color the point with the value=0.0 a different color:

enter image description here

Passing the match var into hue produces the below and removes the 3rd par=3000 value and collapses the plot. I can categorize the outliers I want highlighted a different color. However, the outlier value is removed from the y-axis and plot collapsed..

enter image description here

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
Novice
  • 1,101
  • 4
  • 18
  • 30

1 Answers1

0

Are you sure you want a stripplot? It looks to me like you are actually trying to plot a scatterplot?

Also, I think you want to use a FacetGrid instead of a PairGrid? In that case, it requires to transform your dataframe in "long-form".

Here is what I got:

df2 = df.melt(id_vars=['par','found'], var_name='Test', value_name='AF')

g = sns.FacetGrid(data=df2, col='Test', col_order=['t1','t2'], hue='found',
                  height=5, aspect=.65)

g.map(sns.scatterplot, 'AF','par',
      s=100, linewidth=1, edgecolor="gray", palette="ch:2.5,-.2,dark=.3")

enter image description here

Diziet Asahi
  • 38,379
  • 7
  • 60
  • 75