Search code examples
pythonseaborntransparencyregplot

control seaborn regplot confidence intervals translucency


Anyone has a way to control the degree of translucency of the confidence intervals in seaborn regplot? It's been bugging me (especially for black background plots) for a while and I still could not find anything on that topic.

import pandas as pd
import seaborn as sns
data = pd.DataFrame(np.random.random((100,2)), columns=["x","y"])
sns.regplot('x', 'y', data=data)

Solution

  • You can set the alpha for the confidence interval band using matplotlib.pyplot.setp like:

    import pandas as pd
    import seaborn as sns
    import matplotlib.pyplot as plt
    
    data = pd.DataFrame(np.random.random((100,2)), columns=["x","y"])
    ax = sns.regplot('x', 'y', data=data)
    plt.setp(ax.collections[1], alpha=0.2)
    

    Just for reference, If you want to look at elements of a seaborn plot you can use ax.get_children().