- 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
Plotting distance arrows in technical drawing in Matplotlib
To plot distance arrows in technical drawing in matplotlib, we can use annotate() method with arrow properties.
Steps
Set the figure size and adjust the padding between and around the subplots.
Add a horizontal line across the axis using axhline() method, i.e., y=3.5.
Add a horizontal line across the axis using axhline() method, i.e., y=2.5.
Use annotate() method to draw an arrow line to show the distance and in the very next statement, use annotate() method again to display the distance between two horizontal lines.
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.axhline(3.5) plt.axhline(2.5) plt.annotate( '', xy=(0.5, 3.5), xycoords='data', xytext=(0.5, 2.5), textcoords='data', arrowprops={'arrowstyle': '<->'}) plt.annotate( '$\it{d=1}$', xy=(0.501, 3.0), xycoords='data', xytext=(0.5, 3.5), textcoords='offset points') plt.show()
Output
- Related Articles
- Line plot with arrows in Matplotlib
- Drawing arrows between DOM elements in React JS using react-archer
- Plotting power spectral density in Matplotlib
- Plotting profile histograms in Python Matplotlib
- Drawing average line in histogram in Matplotlib
- Plotting regression and residual plot in Matplotlib
- Plotting animated quivers in Python using Matplotlib
- Plotting histograms against classes in Pandas / Matplotlib
- Plotting an imshow() image in 3d in Matplotlib
- Drawing lines between two plots in Matplotlib
- Plotting grids across the subplots in Python Matplotlib
- Plotting scatter points with clover symbols in Matplotlib
- Plotting Pandas DataFrames in Pie Charts using Matplotlib
- Drawing multiple figures in parallel in Python with Matplotlib
- Drawing a rectangle with only border in Matplotlib

Advertisements