Skip to content

Reinstate ability to set colour palette for slopegraph and delta dots in paired plots for non-group column #218

Open

Description

@mlotinga

Is your feature request related to a problem? Please describe.
In earlier versions of dabest-python, it was possible to simultaneously set the color_col argument to a column in the data (that does not define the groups being compared) alongside a custom_palette. Now setting both of these results in an a KeyError. For example, using the setup from from https://acclab.github.io/DABEST-python/tutorials/08-plot_aesthetics.html:

from scipy.stats import norm # Used in generation of populations.

np.random.seed(9999) # Fix the seed to ensure reproducibility of results.

Ns = 20 # The number of samples taken from each population

# Create samples
c1 = norm.rvs(loc=3, scale=0.4, size=Ns)
c2 = norm.rvs(loc=3.5, scale=0.75, size=Ns)
c3 = norm.rvs(loc=3.25, scale=0.4, size=Ns)

t1 = norm.rvs(loc=3.5, scale=0.5, size=Ns)
t2 = norm.rvs(loc=2.5, scale=0.6, size=Ns)
t3 = norm.rvs(loc=3, scale=0.75, size=Ns)
t4 = norm.rvs(loc=3.5, scale=0.75, size=Ns)
t5 = norm.rvs(loc=3.25, scale=0.4, size=Ns)
t6 = norm.rvs(loc=3.25, scale=0.4, size=Ns)


# Add a `gender` column for coloring the data.
females = np.repeat('Female', Ns/2).tolist()
males = np.repeat('Male', Ns/2).tolist()
gender = females + males

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

# Combine samples and gender into a DataFrame.
df = pd.DataFrame({'Control 1' : c1,     'Test 1' : t1,
                   'Control 2' : c2,     'Test 2' : t2,
                   'Control 3' : c3,     'Test 3' : t3,
                   'Test 4'    : t4,     'Test 5' : t5, 'Test 6' : t6,
                   'Gender'    : gender, 'ID'  : id_col
                  })

np.random.seed(9999) # Fix the seed so the results are replicable.

two_groups_paired = dabest.load(df, idx=("Control 1", "Test 1"), paired="baseline", id_col="ID")

two_groups_paired.mean_diff.plot(color_col="Gender");  # works: default colour palette separates the slopes and delta dots into colours by male/female
two_groups_paired.mean_diff.plot(custom_palette=['red', 'blue']);  # works: colors the delta violin 'blue' (not desired)
two_groups_paired.mean_diff.plot(color_col="Gender", custom_palette=['red', 'blue']);  # fails KeyError: 'Test 1'

Describe the solution you'd like
In previous versions of dabest-python, it was possible to make a plot like the one below, using both color_col and custom_palette together:

Image

Here, the paired groups are Modelled and Scaled, while color_col is used to highlight another variable, using a custom_palette.

The problem seems to be that the use of custom_palette now appears to be focussed on colouring the paired groups instead of allowing its use to highlight another distinction within the data. It seems like this may have been a consequence of the modifications made to address #207. Could the feature to colour by another column (outside the paired groups variable) using a custom palette be reinstated somehow? This is a very useful way to highlight data features, and the flexibility of using custom colours for it is very handy. The option to use custom colours for paired groups is purely aesthetic as far as I can tell (since the groups are already spatially distinguished), and doesn't really add any data analysis value?

dabest-python==2025.10.20

I have also tried using 'color_col' and 'custom_palette' as dict keys inside slopegraph_kwargs, but they aren't recognised. Is there any another existing solution?

Activity

  1. mlotinga commented on Aug 6, 2026

    @mlotinga
    Author

    Evidently, no one else gives a monkeys about this feature.

  2. sangyu commented on Aug 7, 2026

    @sangyu
    Collaborator

    Hi Mike,

    Thanks for flagging this, and sorry for the wait. DABEST is maintained by a small team of scientists doing this alongside full-time research, so turnaround on issues can be slower than we’d like. That said, the custom_palette/color_col interaction is a fair catch, and we’ll get to it as capacity allows. Appreciate your patience.

    Sangyu

  3. mlotinga commented on Aug 16, 2026

    @mlotinga
    Author

    Hi Sangyu,

    Thanks for your reply. I'm aware that this is research software maintained by a small team, and I'm grateful for that. That's also why I have tried to contribute in the past (#188).

    I hope that this issue can gain some attention, as it seems to have arisen from what I perceive as a disconnect between functionality and aesthetics. I feel that the updated aesthetic that has displaced the previous behaviour is actually less useful and more focussed on pretty colours than on plot interpretation.

    More broadly, having been a dabest user for ~4 years, my feeling is that the package is becoming increasingly opinionated, and I'm not sure this is all beneficial to the way it works — many recent updates have completely overhauled the input arguments so that code written in just one or two versions prior is now completely broken. Of course, updates are important and a welcome sign of a healthy package maintenance. However, I'm not convinced all the breaking changes are necessary, and this is one potential example of that. That said, it remains an extremely useful analysis package and I hope it will continue to improve.

    All the best,
    Mike

  4. added a commit that references this issue on Sep 9, 2026
  5. added a commit that references this issue on Sep 10, 2026
  6. drkotireddysaripalli commented on Oct 9, 2026

    @drkotireddysaripalli

    The existing fix in #230 works in a focused three-condition check; the remaining distinction is the installed source, rather than dabest.__version__ alone. The PyPI package and the tested fix both report 2025.10.20.

    I compared the released PyPI package with the immutable bugfix_218 commit ec62d0d, which #230 merged into vnbdev as 6667a1b. For each of paired="baseline" and paired="sequential":

    Palette together with color_col="Gender" PyPI 2025.10.20 Existing fix
    ["red", "blue"] KeyError: 'Test 1' Plot succeeds
    {"Female": "red", "Male": "blue"} Unsupported-dictionary ValueError Plot succeeds
    "Dark2" KeyError: 'Test 1' Plot succeeds

    The list/dictionary checks also verified the eight actual participant slope colours: four red, then four blue. Calls with only color_col, or only custom_palette, succeed in both installations.

    Minimal synthetic example used for the dictionary case:

    import dabest
    import pandas as pd
    
    df = pd.DataFrame({
        "Control 1": [1., 2., 4., 5., 7., 8., 10., 12.],
        "Test 1": [2., 4., 3., 7., 9., 8.5, 13., 14.],
        "Test 2": [3., 5., 6., 8., 8., 11., 15., 14.5],
        "Gender": ["Female"] * 4 + ["Male"] * 4,
        "ID": range(1, 9),
    })
    obj = dabest.load(
        df, idx=("Control 1", "Test 1", "Test 2"),
        paired="baseline", id_col="ID", resamples=500, random_seed=12345,
    )
    obj.mean_diff.plot(
        color_col="Gender", custom_palette={"Female": "red", "Male": "blue"},
        raw_desat=1., contrast_desat=1., delta_text=False,
        slopegraph_kwargs={"jitter": 0},
    )

    Environment: Windows, Python 3.12.14, NumPy 2.1.3, pandas 2.2.3, SciPy 1.15.3, Matplotlib 3.10.9, Seaborn 0.13.2 and Numba 0.61.2. These are actual load/mean_diff.plot calls with isolated installations, not a full test-suite run. The 500 resamples are for this plotting regression only; interval-stability warnings occurred, and this does not validate inferential accuracy. The existing fix is merged into development; this comparison does not establish a new PyPI release containing it.

    Affiliation: Chief Scientist PinnacleAI(R), Pinnacle Blooms Network of Bharath Healthcare P LIMITED, https://www.pinnacleblooms.org/verify

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions