
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to adjust the space between legend markers and labels in Matplotlib?
To adjust the space between legend markers and labels, we can use labelspacing in legend method.
Steps
Plot lines with label1, label2 and label3.
Initialize a space variable to increase or decrease the space between legend markers and label.
Use legend method with labelspacing in the arguments.
To display the figure, use show() method.
Example
from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True plt.plot([0, 1], [0, 1.0], label='Label 1') plt.plot([0, 1], [0, 1.1], label='Label 2') plt.plot([0, 1], [0, 1.2], label='Label 3') space = 2 plt.legend(labelspacing=space) plt.show()
Output
- Related Questions & Answers
- How to adjust the size of a Matplotlib legend box?
- How to adjust the space between Matplotlib/Seaborn subplots for multi-plot layouts?
- How to make two markers share the same label in the legend using Matplotlib?
- How to write text in subscript in the axis labels and the legend using Matplotlib?
- How to change the separation between tick labels and axis labels in Matplotlib?
- Increasing the space for X-axis labels in Matplotlib
- How to change the legend fontname in Matplotlib?
- How to position and align a Matplotlib figure legend?
- How to make markers on lines smaller in Matplotlib?
- How to set legend marker size and alpha in Matplotlib?
- How to add titles to the legend rows in Matplotlib?
- How to add legend to imshow() in Matplotlib?
- How to adjust the branch lengths of a dendrogram in Matplotlib?
- How to create custom markers on a plot in Matplotlib
- How to create a draggable legend in Matplotlib?
Advertisements