Plotting distance arrows in technical drawing in Matplotlib

To plot distance arrows in technical drawing in Matplotlib, we can use the annotate() method with arrow properties. This is particularly useful for creating dimensional annotations in engineering drawings or technical illustrations.

Basic Distance Arrow Example

Here's how to create a simple distance arrow between two horizontal lines ?

import matplotlib.pyplot as plt

# Set figure size and layout
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True

# Draw two horizontal lines
plt.axhline(3.5, color='black', linewidth=2)
plt.axhline(2.5, color='black', linewidth=2)

# Create bidirectional arrow
plt.annotate(
    '', xy=(0.5, 3.5), xycoords='data',
    xytext=(0.5, 2.5), textcoords='data',
    arrowprops={'arrowstyle': '<->', 'color': 'red', 'lw': 1.5}
)

# Add distance label
plt.annotate(
    '$\it{d=1}$', xy=(0.501, 3.0), xycoords='data',
    xytext=(10, 0), textcoords='offset points',
    fontsize=12, ha='left'
)

plt.xlim(0, 2)
plt.ylim(2, 4)
plt.grid(True, alpha=0.3)
plt.title('Distance Arrow in Technical Drawing')
plt.show()

Advanced Distance Arrows

For more complex technical drawings with multiple measurements ?

import matplotlib.pyplot as plt

fig, ax = plt.subplots(figsize=(8, 6))

# Draw a rectangle
rect_x = [1, 4, 4, 1, 1]
rect_y = [2, 2, 4, 4, 2]
ax.plot(rect_x, rect_y, 'k-', linewidth=2)

# Horizontal dimension arrow (bottom)
ax.annotate('', xy=(1, 1.5), xytext=(4, 1.5),
            arrowprops={'arrowstyle': '<->', 'color': 'blue', 'lw': 1.5})
ax.text(2.5, 1.2, '3 units', ha='center', fontsize=12, color='blue')

# Vertical dimension arrow (right)
ax.annotate('', xy=(4.5, 2), xytext=(4.5, 4),
            arrowprops={'arrowstyle': '<->', 'color': 'red', 'lw': 1.5})
ax.text(4.8, 3, '2 units', ha='left', va='center', fontsize=12, color='red')

# Diagonal dimension
ax.annotate('', xy=(1, 2), xytext=(4, 4),
            arrowprops={'arrowstyle': '<->', 'color': 'green', 'lw': 1.5})
ax.text(2.2, 3.2, '$\sqrt{13}$', fontsize=12, color='green', rotation=33)

ax.set_xlim(0, 6)
ax.set_ylim(0, 5)
ax.set_aspect('equal')
ax.grid(True, alpha=0.3)
ax.set_title('Technical Drawing with Multiple Dimensions')
plt.show()

Arrow Styles and Properties

Arrow Style Code Best For
Bidirectional '<->' Distance measurements
Single arrow '->' Direction indicators
Fancy arrow 'fancy' Highlighted dimensions

Customizing Arrow Appearance

You can customize various arrow properties for better visual clarity ?

import matplotlib.pyplot as plt

fig, ax = plt.subplots(figsize=(8, 4))

# Line to measure
ax.plot([1, 5], [3, 3], 'k-', linewidth=3, label='Component')

# Custom arrow with detailed properties
arrow_props = {
    'arrowstyle': '<->',
    'color': 'darkblue',
    'lw': 2,
    'mutation_scale': 20,  # Arrow head size
    'shrinkA': 5,          # Shrink from start point
    'shrinkB': 5           # Shrink from end point
}

ax.annotate('', xy=(1, 2.5), xytext=(5, 2.5), arrowprops=arrow_props)

# Styled dimension text
ax.text(3, 2.2, '4.0 ± 0.1 mm', ha='center', va='top', 
        fontsize=14, fontweight='bold',
        bbox=dict(boxstyle='round,pad=0.3', facecolor='yellow', alpha=0.7))

ax.set_xlim(0, 6)
ax.set_ylim(1.5, 4)
ax.set_title('Customized Technical Dimension Arrow')
ax.legend()
plt.show()

Key Parameters

  • xy − End point of the arrow
  • xytext − Start point of the arrow
  • arrowprops − Dictionary containing arrow styling options
  • textcoords − Coordinate system for text positioning
  • xycoords − Coordinate system for arrow points

Conclusion

Use annotate() with bidirectional arrows ('<->') for technical drawings. Combine with proper text placement and styling to create professional dimensional annotations. Customize arrow properties for enhanced visual clarity in engineering drawings.

Updated on: 2026-03-25T21:14:56+05:30

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements