You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A common flow task is quad gating. I think this example image is probably tool-generated and not done in code, but it is a good example:
Unlike that image, we can also make it more useful if we can show gating per colored condition. However, making a plot with annotations like this is typically at least slightly annoying since it involves a subsequent pandas groupby. We can make a helper function that does a couple things:
Makes a scatter or kdeplot using the seaborn function.
Does a groupby (by whatever the hue column is, if it exists).
Calculates the gated percentage by the hue column.
Draws axvline / axhline at certain gate values and adds annotations in the corners. If there are multiple hues, add multicolored text so you can see e.g. the black population has 25% in this quadrant and the purple has 45%.
Implementation tips
The easiest way to do this is probably as a decorator that captures arguments. I think a clean way to implement this would be something that looks like this type of call:
How do we implement such a thing? A decorator is a function that takes a function and returns a function that does what you want. It probably looks like:
# In rd.flowdefquad_gated(sns_f):
defdecorated(*args, **kwargs):
# Args is the list of positional arguments, kwargs is the keyword arguments.# Start by pulling out the "x_gate" and "y_gate" kwargsx_gate=kwargs['x_gate']
y_gate=kwargs['y_gate']
# strip these keywords out so the seaborn function doesn't get confuseddelkwargs['x_gate']
delkwargs['y_gate']
# Extract the dataframe / x col / y col / hue col variablesdf=args[0] iflen(args) >0elsekwargs['data']
x_col=kwargs['x']
y_col=kwargs['y']
hue_col=kwargs['hue'] if'hue'inkwargselseNone# call the seaborn functiong=sns_f(*args, **kwargs)
# g is now the matplotlib Axes object# TODO: do the groupby gating on df to get percentages# TODO: pull out the hue mapping from the g object# TODO: add axvline, axhline, and annotations in the cornersreturndecorated
I assigned Emma since it looks like you use this type of gate (and can contribute to rushd!), Kasey because you've added stuff before.
The text was updated successfully, but these errors were encountered:
A common flow task is quad gating. I think this example image is probably tool-generated and not done in code, but it is a good example:
Unlike that image, we can also make it more useful if we can show gating per colored condition. However, making a plot with annotations like this is typically at least slightly annoying since it involves a subsequent pandas groupby. We can make a helper function that does a couple things:
hue
column is, if it exists).axvline
/axhline
at certain gate values and adds annotations in the corners. If there are multiple hues, add multicolored text so you can see e.g. the black population has 25% in this quadrant and the purple has 45%.Implementation tips
The easiest way to do this is probably as a decorator that captures arguments. I think a clean way to implement this would be something that looks like this type of call:
How do we implement such a thing? A decorator is a function that takes a function and returns a function that does what you want. It probably looks like:
I assigned Emma since it looks like you use this type of gate (and can contribute to rushd!), Kasey because you've added stuff before.
The text was updated successfully, but these errors were encountered: