HOWTO · Seaborn
How to Create Multiple Line Plot Seaborn
Create and customize multiple Seaborn lines from wide-form or long-form data.
On this page
To create a multiple-line plot with Seaborn, put each series in a column of a pandas DataFrame and pass the frame to lineplot(). For long-form data, map the value and series columns to y and hue. You can then customize line appearance and scale the plot text.
Create Multiple Lines from Wide-Form Data
For five measured series, put each series in its own DataFrame column and pass the frame to lineplot(). The index supplies the x values, and each column becomes a separate line. The following complete example creates the frame and plot:
import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
values = {
"A": [11, 3, 0, 0, 0, 0],
"B": [1, 8, 16, 0, 0, 1],
"C": [0, 0, 3, 12, 0, 0],
"D": [2, 1, 0, 0, 13, 0],
"E": [0, 0, 0, 0, 0, 16],
}
data = pd.DataFrame(values, index=range(6))
ax = sns.lineplot(data=data)
ax.set(xlabel="Index", ylabel="Value", title="Five series")
plt.tight_layout()
plt.show()
The supplied runtime run completed this example successfully with exit code 0 and no stdout. Install pandas, Seaborn, and Matplotlib in your Python environment to run it locally. If your values are already in a NumPy array, pass that array to pd.DataFrame(); numpy.array() is the NumPy constructor for creating an array from values.
Plot Multiple Series from Long-Form Data
Long-form data stores one observation per row, with columns for the x value, series identity, and measured value. Pass those column names as x, hue, and y: Seaborn uses x for horizontal positions, y for vertical values, and hue to draw a separate line for each series.
import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
long_data = pd.DataFrame(
[
(0, "A", 11), (1, "A", 3), (2, "A", 0),
(0, "B", 1), (1, "B", 8), (2, "B", 16),
(0, "C", 0), (1, "C", 0), (2, "C", 3),
],
columns=["x", "series", "value"],
)
ax = sns.lineplot(data=long_data, x="x", y="value", hue="series")
ax.set(title="Three series", ylabel="Value")
plt.tight_layout()
plt.show()
The supplied runtime run completed this second example successfully with exit code 0 and no stdout. Use the wide form when each series already has its own column; use the long form when each row identifies a series and one observation. In either form, give the axes descriptive labels so readers can interpret the plotted values.
Customize Line and Marker Appearance
With long-form data, hue separates the series and a palette assigns their colors. You can also set markers=True and style="series" in lineplot() to show a marker shape for each series, or use a marker choice when you want a shared symbol. Set legend=False when the lines are already identified elsewhere; keeping the legend is useful when it explains the color or marker mapping.
For direct control of line appearance, style the line objects returned by the plot. This keeps marker sizing and edge details in Matplotlib’s line properties, while Seaborn handles series mapping and palette selection:
import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
long_data = pd.DataFrame(
[(x, series, value) for series, values in {
"A": [11, 3, 0], "B": [1, 8, 16], "C": [0, 0, 3]
}.items() for x, value in enumerate(values)],
columns=["x", "series", "value"],
)
ax = sns.lineplot(
data=long_data,
x="x",
y="value",
hue="series",
palette="dark",
legend=False,
)
for line in ax.lines:
line.set_linewidth(2)
line.set_marker("o")
line.set_markersize(7)
line.set_markerfacecolor("white")
line.set_markeredgecolor("red")
line.set_markeredgewidth(1.5)
ax.set(title="Styled series", ylabel="Value")
plt.tight_layout()
plt.show()
The supplied runtime run completed this styling example successfully with exit code 0 and no stdout. Line width controls stroke thickness; marker size controls symbol size; marker face and edge colors distinguish the symbol from the line, and edge width controls the outline thickness. Change the marker shape or palette to suit the chart, and retain a legend whenever readers need it to identify the series.
Adjust Plot Text Size
Set Seaborn’s font scale before creating the plot to enlarge or reduce plot text. A scale above 1 enlarges text relative to the default, while a value below 1 reduces it. The setting applies to the plot’s text elements, including labels and tick text.
import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
sns.set(font_scale=1.3)
data = pd.DataFrame({"A": [2, 4, 3], "B": [1, 3, 5]})
ax = sns.lineplot(data=data, markers=True)
ax.set(title="Scaled plot text", xlabel="Index", ylabel="Value")
plt.tight_layout()
plt.show()
The supplied runtime run completed this final example successfully with exit code 0 and no stdout. Adjust font_scale to fit the figure and its labels in the space available.