How to change the line color in a Seaborn linear regression jointplot?

To change the line color in a Seaborn linear regression jointplot, we can use the joint_kws parameter in the jointplot() method. This allows us to customize the appearance of the regression line by passing styling arguments.

Steps

  • Set the figure size and adjust the padding between and around the subplots
  • Create x and y data points using NumPy to make a Pandas DataFrame
  • Use jointplot() method with joint_kws parameter to specify line color
  • Display the figure using show() method

Example

Here's how to create a regression jointplot with a custom line color ?

import seaborn as sns
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd

plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True

# Create sample data
X = np.random.randn(1000)
Y = 0.2 * np.random.randn(1000) + 0.5

# Create DataFrame
df = pd.DataFrame(dict(x=X, y=Y))

# Create jointplot with green regression line
g = sns.jointplot(x="x", y="y", data=df, kind='reg', height=3.5, joint_kws={'color':'green'})

plt.show()

Customizing with Different Colors

You can use various color options for the regression line ?

import seaborn as sns
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd

# Create sample data
X = np.random.randn(500)
Y = 0.3 * X + 0.1 * np.random.randn(500)

df = pd.DataFrame({'x': X, 'y': Y})

# Using different color options
# Red regression line
g1 = sns.jointplot(x="x", y="y", data=df, kind='reg', joint_kws={'color':'red'})
plt.show()

# Using hex color code
g2 = sns.jointplot(x="x", y="y", data=df, kind='reg', joint_kws={'color':'#FF6B35'})
plt.show()

# Using RGB tuple
g3 = sns.jointplot(x="x", y="y", data=df, kind='reg', joint_kws={'color':(0.2, 0.4, 0.8)})
plt.show()

Additional Styling Options

You can combine line color with other styling parameters ?

import seaborn as sns
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd

# Create sample data
X = np.random.randn(300)
Y = 0.5 * X + 0.2 * np.random.randn(300)

df = pd.DataFrame({'x': X, 'y': Y})

# Customize line color, width, and style
g = sns.jointplot(
    x="x", y="y", 
    data=df, 
    kind='reg', 
    height=4,
    joint_kws={
        'color': 'purple',
        'line_kws': {'linewidth': 3, 'linestyle': '--'}
    }
)

plt.show()

Key Parameters

Parameter Description Example Values
joint_kws Dictionary of keyword arguments for joint plot {'color': 'red'}
color Color of the regression line 'green', '#FF6B35', (0.2, 0.4, 0.8)
line_kws Additional line styling options {'linewidth': 2}

Conclusion

Use the joint_kws parameter with color key to change regression line color in Seaborn jointplots. You can specify colors using names, hex codes, or RGB tuples for complete customization.

Updated on: 2026-03-25T21:37:14+05:30

978 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements