sns regplot cuts of my first and last datapoint

Viewed 348

I've been working on some regplots and noticed that when I use sns.regplot seaborn cuts off my last and first datapoints. Here is my code. I know that I can set the xlim and ylim manually and therefore can circumvent this issue, but I was wondering if there is a more elegant way to solve this problem! Thanks so much in advance! Looking forward to hearing your solutions!

for rab, hrab, rep1, rep2 in zipped_final: 
    with sns.axes_style(style='ticks'):
        fig, axes = plt.subplots(1,3, figsize =(18,6))
        sns.regplot(
            ax = axes[0],
            data = rablog_df,
            x = 'expected ratio',
            y = rab,
            ci = None)
        axes[0].set_title('LOQ' + ' ' + f'{rab}', fontsize = 16)
        axes[0].annotate('10 amol', xy =(rablog_df['expected ratio'][8], rablog_df[rab][8]))

         
        sns.regplot(
            ax = axes[1],
            data = rabhlog_df,
            x = 'expected concentration',
            y = hrab,
            ci = None)
        axes[1].set_title('LOD' + ' ' + f'{rab}', fontsize = 16)
        axes[1].annotate('10 amol', xy =(rabhlog_df['expected concentration'][8], rabhlog_df[hrab][8]))
        
        sns.regplot(
            ax = axes[2],
            data = rabreplog_df,
            x = rep1,
            y = rep2,
            ci = None)
        axes[2].set_title(f'{rab}', fontsize = 16)
        axes[2].annotate('10 amol', xy =(rabreplog_df[rep1][8], rabreplog_df[rep2][8]))
        sns.despine(offset = 20, trim = True)

here a picture of the plot:

enter image description here

1 Answers

You can use clip_on keyword of the scatterplot to turn off clipping. Here is an example:

import seaborn as sns

penguins = sns.load_dataset('penguins')
torgersen = penguins[(penguins['island'] == 'Torgersen') & (penguins['sex'] == 'Male')]
with sns.axes_style(style='ticks'):
    sns.regplot(data=torgersen, x='flipper_length_mm', y='bill_length_mm', ci=None, 
                scatter_kws={'clip_on': False})
    sns.despine(offset=20, trim=True)

sns.regplot without clipping scatter dots

Related