sns.lineplot()
Line plot for visualizing trends over a continuous variable (e.g., time series).
Seaborn sns.lineplot()
— Complete Guide
The sns.lineplot()
function in Seaborn is a fundamental tool for visualizing relationships and trends between numerical variables, especially over a continuous interval like time. It draws a line that connects data points, helping you spot trends, patterns, and deviations.
Function Signature
sns.lineplot(
data=None,
*,
x=None,
y=None,
hue=None,
style=None,
size=None,
palette=None,
hue_order=None,
size_order=None,
sizes=None,
dashes=True,
markers=None,
legend="auto",
ax=None,
**kwargs
)
🗂️ Key Parameters
🔑 Primary Parameters
data
: The dataset (Pandas DataFrame or array-like) to plot.x
: Variable plotted on the x-axis (often time or ordered values).y
: Variable plotted on the y-axis.
🎨 Aesthetic Mappings
hue
: Differentiate lines by color.style
: Differentiate lines by pattern (solid, dashed) based on a categorical variable.size
: Vary line thickness based on a numeric or categorical variable.palette
: Specify the color palette forhue
.
📏 Order and Sizes
hue_order
: Order of categories forhue
.size_order
: Order forsize
.sizes
: Range for line widths (e.g.,(1, 5)
).
➿ Line Patterns & Markers
dashes
: Whether to use different dash styles forstyle
. Can beTrue
,False
, or a dict.markers
: Add point markers to the line for each observation.
🗂️ Legend
legend
:"auto"
,"brief"
,"full"
orFalse
to control legend display.
🧩 Axes
ax
: Matplotlib Axes object to draw the plot on.
🎛️ Additional Styling (*kwargs
)
Supports Matplotlib keyword arguments for extra customization: alpha
(transparency), linewidth
, linestyle
, etc.
📌 Dataset Preparation
Let’s use the built-in Flights dataset as an example.
import seaborn as sns
import matplotlib.pyplot as plt
# Load example dataset
flights = sns.load_dataset('flights')
flights.head()
year month passengers
0 1949 Jan 112
1 1949 Feb 118
2 1949 Mar 132
3 1949 Apr 129
4 1949 May 121
.. ... ... ...
139 1960 Aug 606
140 1960 Sep 508
141 1960 Oct 461
142 1960 Nov 390
143 1960 Dec 432
[144 rows x 3 columns]
🚩 Examples
1️⃣ Basic Line Plot
sns.lineplot(data=flights, x='year', y='passengers')
plt.title("Basic Line Plot")
plt.show()
Use Case: Show trend over time.

2️⃣ Line Plot with hue
sns.lineplot(data=flights, x='year', y='passengers', hue='month')
plt.title("Line Plot with Hue")
plt.show()
Key Parameter: hue
differentiates lines by color.

3️⃣ Line Plot with style
sns.lineplot(data=flights, x='year', y='passengers', hue='month', style='month')
plt.title("Line Plot with Hue and Style")
plt.show()
Key Parameter: style
uses different line patterns (dashed, solid).

4️⃣ Line Plot with size
sns.lineplot(data=flights, x='year', y='passengers', hue='month', size='month', sizes=(1, 5))
plt.title("Line Plot with Variable Line Widths")
plt.show()
Key Parameter: size
controls line thickness.

5️⃣ Custom palette
sns.lineplot(data=flights, x='year', y='passengers', hue='month', palette='tab10')
plt.title("Line Plot with Custom Palette")
plt.show()

6️⃣ Ordered hue_order
months_order = ['January', 'February', 'March', 'April', 'May', 'June',
'July', 'August', 'September', 'October', 'November', 'December']
sns.lineplot(
data=flights,
x='year',
y='passengers',
hue='month',
hue_order=months_order,
palette='tab10'
)
plt.title("Line Plot with Ordered Hue")
plt.show()

7️⃣ Add Markers
sns.lineplot(
data=flights,
x='year',
y='passengers',
hue='month',
style='month',
markers=True
)
plt.title("Line Plot with Markers")
plt.show()

8️⃣ Control Dashes
sns.lineplot(
data=flights,
x='year',
y='passengers',
hue='month',
style='month',
dashes=False # Use solid lines only
)
plt.title("Line Plot with Solid Lines")
plt.show()

9️⃣ Combine hue
, style
, size
, and Markers
sns.lineplot(
data=flights,
x='year',
y='passengers',
hue='month',
style='month',
size='passengers',
sizes=(1, 5),
markers=True,
dashes=True
)
plt.title("Comprehensive Line Plot")
plt.show()

🔟 Transparency
sns.lineplot(data=flights, x='year', y='passengers', hue='month', alpha=0.7)
plt.title("Line Plot with Transparency")
plt.show()

🧑💻 Use Cases for Data Scientists
- Trend Analysis
- Time Series Analysis
- Model Validation
- Group Comparison
Understand changes in key metrics over time.
Visualize seasonality, cycles, and long-term patterns.
Plot actual vs. predicted values for regression models.
Compare trends across multiple categories.
✔️ Practical Notes
- Dealing with Overplotting:
- Customize Markers & Dashes:
- Faceting for Large Groups:
- Legend Control:
- Custom Sizes:
Use alpha
for transparency or style
for different line patterns.
Combine markers
and dashes
for better readability.
Use relplot(kind="line")
to facet by col
or row
.
Use legend="brief"
or legend=False
for simpler legends.
Use sizes=(min, max)
for meaningful line width scaling.
📌 References in Your ML Workflow
✅ EDA: Spot trends in time series or continuous data.
✅ Visualization: Present clear trend plots.
✅ Model Evaluation: Compare model output vs. actuals.
🔑 Summary:
sns.lineplot()
is your go-to function for creating powerful trend and relationship visualizations — ideal for time series analysis, comparing multiple groups, and validating model performance.