Search code examples
matplotlibplotseabornscatter-plot

How to remove the whitespaces between points in scatterplot


I have used the scatterplot command to make a plot of nurse schedules, however whenever the points are close, there is this annoying whitespace, which I would like to get rid of. An example:

enter image description here

So whenever the points are close there appear this white gap...

To plot the red dots I have used this command:

sns.scatterplot(x='xaxis', y='nurses', data=df_plot, marker=',', color='r', s=400,ci=100)

Solution

  • It looks like your markers are being drawn with white edges. You can remove these using edgecolor='None' as an option to sns.scatterplot.

    sns.scatterplot(x='xaxis', y='nurses', data=df_plot,
                    marker=',', color='r', s=400, ci=100, edgecolor='None')
    

    A small example to demonstrate this point:

    import matplotlib.pyplot as plt
    import seaborn as sns
    
    fig, (ax1, ax2) = plt.subplots(ncols=2)
    tips = sns.load_dataset("tips")
    
    sns.scatterplot(ax=ax1, data=tips, x="total_bill", y="tip")
    sns.scatterplot(ax=ax2, data=tips, x="total_bill", y="tip", edgecolor='None')
    

    enter image description here