
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
Align Rows in a Matplotlib Legend with 2 Columns
To align rows in a matplotlib legend with 2 columns, we can take the following steps
- Set the figure size and adjust the padding between and around the subplots.
- Using plot() method, plot lines with the labels line1, line2 and line3.
- Place a legend on the figure with two columns. Use ncol=2.
- To display the figure, use show() method.
Example
from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True plt.plot([1, 2, 3], label="line1") plt.plot([3, 2, 1], label="line2") plt.plot([2, 3, 1], label="line3") plt.legend(ncol=2, loc="upper right") plt.show()
Output
Advertisements