Write, Run & Share Seaborn code online using OneCompiler's Seaborn online compiler for free. It's one of the robust, feature-rich online compilers for the Seaborn statistical visualization library, running on Python 3.12 with NumPy, Pandas, and Matplotlib pre-installed. Plots are streamed live into the browser — plt.show() opens a real Tk window inside the run sandbox and you see the chart in the output panel. The editor shows sample boilerplate code when you choose language as Seaborn and start coding.
Seaborn is a high-level statistical plotting library built on top of Matplotlib. It was created by Michael Waskom in 2012 to give Python users the kind of clean defaults and dataset-oriented API that R users had with ggplot2. The pitch is simple — you pass it a Pandas DataFrame and a column name, and Seaborn handles the colour palette, the binning, the confidence intervals, and the legend for you. Underneath it's still Matplotlib, so anything Seaborn doesn't expose you can still tweak through plt.
NumPy, Pandas, Matplotlib, and Seaborn are pre-installed. To add anything else (scikit-learn, scipy, statsmodels…), open requirements.txt in the file tree and add one package per line — the first run installs them, subsequent runs are cached.
seaborn
pandas
numpy
scikit-learn
Seaborn ships with a handful of demo datasets (tips, iris, penguins, titanic, flights) — perfect for trying things out without hunting for CSVs.
import seaborn as sns
import matplotlib
matplotlib.use("TkAgg")
import matplotlib.pyplot as plt
sns.set_theme(style="whitegrid")
tips = sns.load_dataset("tips")
sns.scatterplot(data=tips, x="total_bill", y="tip", hue="time")
plt.title("Tips vs total bill")
plt.show()
set_theme() is the one line you'll repeat at the top of most Seaborn scripts. It picks a style, a colour palette, and font sizes in one go.
import seaborn as sns
import matplotlib.pyplot as plt
# Styles: 'darkgrid' (default), 'whitegrid', 'dark', 'white', 'ticks'
# Contexts: 'paper', 'notebook' (default), 'talk', 'poster' — controls scale
sns.set_theme(style="darkgrid", context="talk", palette="Set2")
# Try a built-in palette
sns.palplot(sns.color_palette("rocket", 8))
plt.show()
histplot for raw counts, kdeplot for a smoothed density estimate, displot for a figure-level wrapper that combines both.
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
data = np.random.normal(0, 1, 1000)
sns.histplot(data, kde=True, color="#55A868", bins=30)
plt.title("Histogram with KDE overlay")
plt.show()
# Compare two distributions side by side
penguins = sns.load_dataset("penguins")
sns.kdeplot(data=penguins, x="flipper_length_mm", hue="species", fill=True, alpha=0.4)
plt.show()
These are the workhorse charts for comparing a numeric variable across categories.
import seaborn as sns
import matplotlib.pyplot as plt
tips = sns.load_dataset("tips")
# Box plot
sns.boxplot(data=tips, x="day", y="total_bill", hue="smoker")
plt.title("Total bill by day and smoker")
plt.show()
# Violin plot (boxplot + KDE)
sns.violinplot(data=tips, x="day", y="total_bill", hue="sex", split=True)
plt.show()
# Bar plot with built-in confidence intervals
sns.barplot(data=tips, x="day", y="tip", hue="sex", errorbar="sd")
plt.show()
Use relplot to facet a scatter or line chart across columns or rows — a small multiples chart in one line.
import seaborn as sns
import matplotlib.pyplot as plt
tips = sns.load_dataset("tips")
# Scatter with size and hue encodings
sns.scatterplot(data=tips, x="total_bill", y="tip",
hue="day", size="size", sizes=(40, 200), alpha=0.7)
plt.show()
# Faceted relplot — one panel per smoker value
sns.relplot(data=tips, x="total_bill", y="tip",
col="smoker", hue="sex", kind="scatter", height=4)
plt.show()
regplot overlays a linear fit (and its confidence band) on a scatter plot. lmplot is the faceted version.
import seaborn as sns
import matplotlib.pyplot as plt
tips = sns.load_dataset("tips")
sns.regplot(data=tips, x="total_bill", y="tip", scatter_kws={"alpha": 0.5})
plt.title("Tip vs total bill — linear fit")
plt.show()
# Faceted regression — one fit per smoker x sex
sns.lmplot(data=tips, x="total_bill", y="tip",
col="smoker", hue="sex", height=4)
plt.show()
heatmap is the standard tool for visualizing a matrix of numbers — most often the correlation matrix of a DataFrame.
import seaborn as sns
import matplotlib.pyplot as plt
iris = sns.load_dataset("iris")
corr = iris.drop(columns="species").corr()
sns.heatmap(corr, annot=True, cmap="coolwarm", center=0, fmt=".2f")
plt.title("Iris feature correlations")
plt.show()
One line to scan an entire dataset for relationships and per-class distributions.
import seaborn as sns
import matplotlib.pyplot as plt
penguins = sns.load_dataset("penguins")
sns.pairplot(penguins, hue="species", diag_kind="kde", height=2.2)
plt.show()
Seaborn returns plain Matplotlib axes — anything you'd do with plt or ax.set_* still works.
import seaborn as sns
import matplotlib.pyplot as plt
tips = sns.load_dataset("tips")
fig, ax = plt.subplots(figsize=(8, 5))
sns.boxplot(data=tips, x="day", y="total_bill", ax=ax)
ax.set_title("Total bill by day", fontsize=14)
ax.set_ylabel("USD")
ax.axhline(tips["total_bill"].mean(), color="red", linestyle="--", label="mean")
ax.legend()
plt.show()