- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
Line plot with arrows in Matplotlib
To plot with arrows in matplotlib, we can use arrow() method.
Steps
- Create x and y data points using numpy.
- Plot x and y with color=red and linewidth = 1.
- Use arrow method to add an arrow to the axes. The first two values in the arguments are the coordinates of the arrow base and the next two values are for the length of the arrow along X and Y direction.
- To display the figure, use show() method.
Example
from matplotlib import pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True x = np.linspace(-2, 2, 100) y = np.sin(x) plt.plot(x, y, c='b', lw=1) plt.arrow(0, 0, 0.01, np.sin(0.01), shape='full', lw=10, length_includes_head=True, head_width=.05, color='r') plt.show()
Output
- Related Articles
- How to annotate the points on a scatter plot with automatically placed arrows in Matplotlib?
- How to plot a smooth line with matplotlib?
- Plot a Line Graph for Pandas Dataframe with Matplotlib?
- How to plot a line (polygonal chain) with matplotlib with minimal smoothing?
- How to animate a line plot in Matplotlib?
- Plotting distance arrows in technical drawing in Matplotlib
- How to plot a 3D continuous line in Matplotlib?
- How to plot a gradient color line in matplotlib?
- Getting vertical gridlines to appear in line plot in matplotlib
- How to plot a line in Matplotlib with an interval at each data point?
- Plot numpy datetime64 with Matplotlib
- Plot Matplotlib 3D plot_surface with contour plot projection
- How to plot a line graph from histogram data in Matplotlib?
- Plot a multicolored line based on a condition in Python Matplotlib
- Legend with vertical line in matplotlib

Advertisements