Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

keep seaborn.heatmap's cmap as **kwargs #75

Open
kandabarau opened this issue Nov 25, 2024 · 3 comments
Open

keep seaborn.heatmap's cmap as **kwargs #75

kandabarau opened this issue Nov 25, 2024 · 3 comments

Comments

@kandabarau
Copy link

sns.heatmap(df, cmap=colors, ax=ax, xticklabels=False,

I wasnt able to customize the plot_waterfall colors since cmap parameter of seaborn.heatmap is hardcoded.

wouldnt hurt to:

cmap = kwargs.get('cmap', colors)

sns.heatmap(df, ax=ax, xticklabels=False,cbar=False, vmin=0, vmax=len(colors), **kwargs)

or any more elegant solution - I am not that good with python.

@sbslee
Copy link
Owner

sbslee commented Nov 27, 2024

@kandabarau,

Thank you for opening this issue! Am I correct in understanding that you want to provide your own colors variable? Please note that this method does not currently support such customization, as the definition of colors is not straightforward and might cause confusion for users:

fuc/fuc/api/pymaf.py

Lines 3268 to 3271 in 7b0fbfb

colors = list(reversed(NONSYN_COLORS + ['k', 'lightgray']))
sns.heatmap(df, cmap=colors, ax=ax, xticklabels=False,
cbar=False, vmin=0, vmax=len(colors), **kwargs)

Could you share more details about how you would like to customize the colors in this case?

@kandabarau
Copy link
Author

kandabarau commented Nov 28, 2024

@kandabarau,

Thank you for opening this issue! Am I correct in understanding that you want to provide your own colors variable? Please note that this method does not currently support such customization, as the definition of colors is not straightforward and might cause confusion for users:

fuc/fuc/api/pymaf.py

Lines 3268 to 3271 in 7b0fbfb

colors = list(reversed(NONSYN_COLORS + ['k', 'lightgray']))
sns.heatmap(df, cmap=colors, ax=ax, xticklabels=False,
cbar=False, vmin=0, vmax=len(colors), **kwargs)

Could you share more details about how you would like to customize the colors in this case?

hi @sbslee

I already have this working for me:

you hardcoded colors = list(reversed(NONSYN_COLORS + ['k', 'lightgray'])) in your plot_waterfall functions body, I have pulled it as default for the new cmap parameter:

def plot_waterfall(self, count=10, keep_empty=False, samples=None, ax=None,
        cmap:list = None, figsize=None, **kwargs
                   ):
    if cmap is None:
        cmap = list(reversed(NONSYN_COLORS + ['k', 'lightgray']))

    sns.heatmap(df, ax=ax, xticklabels=False, cbar=False, vmin=0, vmax=len(cmap), cmap=cmap, **kwargs)

I named it cmap to prevent same parameter name be passed to kwargs. Can be more delicate or python-ish. I am not good with python.

so I can call plot_waterfall with my own cmap

I did similar to

def plot_tmb(
        self, samples=None, width=0.8, ax=None, figsize=None, color:list = None, **kwargs
    ):
        if color is None:
            color = NONSYN_COLORS

        df.plot.bar(stacked=True, ax=ax, width=width, legend=False,
            color=color, **kwargs)

and to

def plot_genes(self, mode='variants', count=10, flip=False, ax=None, figsize=None, color:list = None,
               **kwargs
               ):
    if color is None:
        color = NONSYN_COLORS
        
    if mode == 'variants':
        color = color
    elif mode == 'samples':
        color = color + ['k']
    else:
        raise ValueError(f'Found incorrect mode: {mode}')

    df.plot(
        kind=kind, ax=ax, stacked=True, legend=False,
        color=color, **kwargs
    )

and it works fine. seemless if you stick to defaults and flexible if somebody uses their own colors.

what do you think?

Bests,
Sergey

@sbslee
Copy link
Owner

sbslee commented Nov 30, 2024

@kandabarau,

Thanks for the detailed explanation!

I already have this working for me

Glad to hear that you got it working for you. I will review your proposal and let you know, but in the meantime I think your approach makes sense and I agree with defining your own custom functions for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants