- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 can I draw inline line labels in Matplotlib?
To draw inline labels in Matplotlib, we can use labelLines() method. −
Steps
- Set the figure size and adjust the padding between and around the subplots.
- Create random data points x using numpy and a list of data points, A.
- Iterate the list of A, and plot X and a (iterated item) with label.
- Label all the lines with their respective legends, for lines drawn.
- To display the figure, use show() method.
Example
import numpy as np from matplotlib import pyplot as plt from labellines import labelLines plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True X = np.linspace(0, 1, 500) A = [1, 2, 5, 10, 20] for a in A: plt.plot(X, np.arctan(a*X), label=str(a)) labelLines(plt.gca().get_lines(), zorder=2.5) plt.show()
Output
- Related Articles
- How can I draw a scatter trend line using Matplotlib?
- How can I rotate xtick labels through 90 degrees in Matplotlib?
- How can I cycle through line styles in Matplotlib?
- How can I create a stacked line graph with matplotlib?
- How can I make a simple 3D line with Matplotlib?
- How to draw rounded line ends using Matplotlib?
- How can I make the xtick labels of a plot be simple drawings using Matplotlib?
- How to draw a line outside of an axis in Matplotlib?
- How do I customize the display of edge labels using networkx in Matplotlib?
- Can I give a border to a line in Matplotlib plot function?
- How to draw an average line for a scatter plot in MatPlotLib?
- How to change the separation between tick labels and axis labels in Matplotlib?
- How can I show figures separately in Matplotlib?
- How can I plot hysteresis threshold in Matplotlib?
- Automatically run %matplotlib inline in IPython Notebook

Advertisements