VOOZH about

URL: https://www.geeksforgeeks.org/python/how-change-the-vertical-spacing-between-legend-entries-in-matplotlib/

⇱ How Change the vertical spacing between legend entries in Matplotlib? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How Change the vertical spacing between legend entries in Matplotlib?

Last Updated : 23 Jul, 2025

Prerequisites: Matplotlib

In this article, we will see how can we can change vertical space between labels of a legend in our graph using matplotlib, Here we will take two different examples to showcase our graph.

Approach:

  • Import required module.
  • Create data.
  • Change the vertical spacing between labels.
  • Normally plot the data.
  • Display plot.

Implementation:

Example 1:

In this example, we will draw different lines with the help of matplotlib and Use the labelspacing argument to plt.legend() to change the vertical space between labels.

Output:

👁 Image

Example 2:

In this example, we will draw a Vertical line with the help of matplotlib and Use the labelspacing argument to plt.legend() to change the vertical space between labels.

Output:

👁 Image
Comment
Article Tags: