Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save meysampg/7547cee1888d46307d58eafa1795268b to your computer and use it in GitHub Desktop.
Save meysampg/7547cee1888d46307d58eafa1795268b to your computer and use it in GitHub Desktop.
Regression Plot with Confidence Interval in Python + Matplotlib + Seaborn
import matplotlib.pyplot as plt
import seaborn as sns
def parse_points(s):
return map(lambda x: map(int, x.strip().split(",")), filter(len, s.split("\n")))
def get_xy(points):
x = []
y = []
for i in points:
t = list(i)
x.append(t[0])
y.append(t[1])
return x, y
a = """
1,10
2,20
3,30
"""
b = """
1,50
2,60
3,70
"""
xa, ya = get_xy(parse_points(a))
xb, yb = get_xy(parse_points(b))
fig, axs = plt.subplots(figsize=(15, 10))
plt.title("A Compare (CI=95%)")
plt.xlabel("X-Axis")
plt.ylabel("Y-Axis")
sns.regplot(x=xa, y=ya, color='blue', ax=axs, label="A")
sns.regplot(x=xb, y=yb, color='green', ax=axs, label="B")
plt.legend()
@meysampg
Copy link
Author

sample

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment