
- 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 make several legend keys to the same entry in Matplotlib?
To make several legend keys to the same entry in Matplotlib, we can take the following steps −
- Set the figure size and adjust the padding between and around the subplots.
- Plot line1 and line2 using plot() method.
- Use legend() method to place a legend over the plot with numpoints=1
- To display the figure, use show() method.
Example
import matplotlib.pyplot as plt from matplotlib.legend_handler import HandlerTuple plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True p1, = plt.plot([1, 2.5, 3], 'r-d') p2, = plt.plot([3, 2, 1], 'k-o') l = plt.legend([(p1, p2)], ['Two keys'], numpoints=1, handler_map={tuple: andlerTuple(ndivide=None)}) plt.show()
Output
- Related Questions & Answers
- How to make two markers share the same label in the legend using Matplotlib?
- How to make several plots on a single page using Matplotlib?
- How to make several plots on a single page using Matplotlib(Python)?
- How to make several plots on a single page using matplotlib in Python?
- How to change the legend fontname in Matplotlib?
- How to make two histograms have the same bin width in Matplotlib?
- How to add titles to the legend rows in Matplotlib?
- How to add legend to imshow() in Matplotlib?
- How do I show the same Matplotlib figure several times in a single IPython notebook?
- Adding a legend to a Matplotlib boxplot with multiple plots on the same axis
- How to create a draggable legend in Matplotlib?
- How to show legend elements horizontally in Matplotlib?
- How to annotate several points with one text in Matplotlib?
- How to set the font size of Matplotlib axis Legend?
- How to adjust the size of a Matplotlib legend box?
Advertisements