Colors in paired data plots

102 views
Skip to first unread message

silvia marchesotti

unread,
Feb 12, 2020, 3:39:29 AM2/12/20
to estimationstats
Hello,

first, thank you very much for sharing this great tool! 
I've just started using DABEST for python and I'm struggling to change the lines color in paired data plots: passing arguments to slopegraph_kwargs work fine for linewidth, linestyle, etc., but not for color. Also, is there a way to change the color of the distribution?

Thank you very much in advance!


Joses Ho

unread,
Feb 13, 2020, 4:19:22 AM2/13/20
to estimat...@googlegroups.com
Hi Silvia,

This google groups is specifically meant for users of the estimationstats.com webapp. Nevertheless we can offer a possible solution here.


You can control the color of the slopegraph lines with the `custom_palette` keyword.

If you want all the slopegraph lines to be the same color, you should create a "dummy" variable, assign it as the `color_col`, then pass a custom dictionary as the palette:

import numpy as np
import pandas as pd
import dabest

# The number of samples
Ns = 20
# Create samples
c1 = norm.rvs(loc=3, scale=0.4, size=Ns)
t1 = norm.rvs(loc=3.5, scale=0.5, size=Ns)

# Add an `id` column for paired data plotting.
id_col = pd.Series(range(1, Ns+1))

# Create the DataFrame.
df = pd.DataFrame({'Control 1' : c1,     'Test 1' : t1,
                   'dummy': np.repeat("not_relevant", len(c1)), # the dummy column.
                   'ID'  : id_col
                  })

# Load into dabest
two_groups_paired = dabest.load(df,
                                idx=("Control 1", "Test 1"),
                                paired=True, id_col="ID")

# Create plot
my_color_palette = {"not_relevant" : "blue"} # change the color here.
two_groups_paired.mean_diff.plot(color_col="dummy", custom_palette= my_color_palette);


Also, is there a way to change the color of the distribution?

Unfortunately not. If the individual categories aren't assigned any color, the bootstrap distribution remains grey. I suppose an argument could be made about allowing the user to alter the distribution color at will, but I'm not sure of the benefits of that versus trying to uphold or establish a design language where the distribution color is tied to categorical identity.

For future questions relating to the Python library, please create an issue at https://github.com/ACCLAB/DABEST-python/issues, with a copy-pastable example.

Hope this helps!
Reply all
Reply to author
Forward
0 new messages