How to add labels to plot in Matplotlib

1 min

Adding labels will help your chart to become more understandable.

By adding the label="Column 1" parameter, we specify its label.

fig, axes = plt.subplots(1,1, figsize=(8,6))

# Here the label parameter will define the label
axes.plot(df.index, df["col1"], label="Column 1")

# The legend method will add the legend of labels to your plot
axes.legend()

fig.tight_layout()
plt.show()
Adding labels

More on plots

If you want to know more about how to add labels, plot different types of plots, etc... checkout the other articles I wrote on the topic, just here :

Matplotlib - The Python You Need
We gathered the only Python essentials that you will probably ever need.