API Reference

ArrowETC module for creating multi-segmented or curved arrows with explicit vertex control.

This module defines the ArrowETC class, which allows building complex polygonal shapes by connecting multiple line segments in sequence or by following a smooth Bezier curve. It can produce classic straight arrows with optional arrowheads, segmented rectangles, or smoothly curved arrows ideal for connectors, annotations, flowcharts, or technical diagrams.

ArrowETC stores extensive metadata for each arrow, including segment lengths, angles, and a complete set of polygon vertices outlining the arrow body. These attributes remain accessible after construction, enabling downstream tasks such as collision detection, dynamic alignment, or generating custom labels tied to specific arrow joints.

WARNING: ArrowETC assumes arrows or segmented shapes are plotted in an equal aspect ratio. The saved or displayed arrow polygon does not automatically account for distorted aspect ratios—if you use an unequal aspect ratio (e.g., ax.set_aspect(‘auto’)), your shapes may appear skewed. It is your responsibility to either:

  1. ensure plots using ArrowETC have an equal aspect ratio, or

  2. manually transform the arrow vertices to compensate for an intended uneven aspect ratio.

Features

  • Explicit calculation of each vertex, including miter joints at corners.

  • Optional smooth Bezier curves to create curved arrows.

  • Supports straight, multi-bend, or smoothly curved paths with arbitrary angles.

  • Optional flared arrowhead at the final path point.

  • Suitable for creating segmented rectangles (shaft-only shapes) by disabling the arrowhead.

  • Stores metadata such as: - self.vertices: polygon vertex coordinates, - self.segment_lengths: lengths of all segments (for straight paths), - self.path_angles: angles each segment makes with the x-axis.

Examples

Basic straight arrow with head:

>>> from logictree.ArrowETC import ArrowETC
>>> arrow = ArrowETC(path=[(0, 0), (0, 5)], arrow_width=1.5, arrow_head=True)
>>> arrow.save_arrow(name='straight_arrow.png')

Curved Bezier arrow with head:

>>> curved_arrow = ArrowETC(path=[(0, 0), (2, 4), (4, 0)], arrow_width=0.8, arrow_head=True, bezier=True)
>>> curved_arrow.save_arrow(name='curved_arrow.png')

class arrowetc.arrowetc.ArrowETC(path, arrow_width, arrow_head=True, ec='grey', fc='white', lw=1.5, ls='-', zorder=100, bezier=False, n_bezier=400, close_butt=True)

Bases: object

An arrow object with detailed vertex control for straight or curved multi-segmented arrows.

ArrowETC can build arrows from a series of straight line segments or generate a smooth Bezier curve through path points. It stores every vertex coordinate explicitly, making it easy to generate complex arrows with multiple joints, gentle curves, or advanced layouts. Unlike matplotlib’s FancyArrow, it provides direct access to the computed arrow geometry for alignment, layout, and metadata tasks.

Parameters:
  • path (list of tuple of FloatLike or int) – List of points defining the arrow path. Each tuple represents a control point. The first point is the “butt” (tail), and the last point is the arrow “head”.

  • arrow_width (FloatLike or int) – Width of the arrow shaft in data coordinates.

  • arrow_head (bool, optional) – If True, an arrowhead is added at the end of the path. If False, the arrow ends with a flat edge.

  • ec (str, optional) – The edge color of your arrow. Default is “grey”.

  • fc (str, optional) – The face color of your arrow. Default is “white”.

  • lw (FloatLike, optional) – The line width of your arrow. Default is 1.5.

  • ls (str, optional) – The line style of your arrow. Defuault is “-“.

  • zorder (int, optional) – The zorder of your arrows. Default is 100.

  • bezier (bool, optional) – If True, constructs the arrow along a smooth Bezier curve interpolated through the path points. If False, the arrow uses straight line segments. Default is False.

  • n_bezier (int, optional) – Number of points used to sample the Bezier curve if bezier=True. Increase this value if you see jagged tips or insufficient curve resolution. Default is 300.

  • close_butt (bool, optional) – If True, the first vertex will also be included as the final vertex to draw a segment at the butt of the arrow. If False, no segment will be drawn for the butt. Default True.

path

The input path defining the arrow’s geometry.

Type:

list of tuple

x_path

X-coordinates of the path points.

Type:

list of FloatLike

y_path

Y-coordinates of the path points.

Type:

list of FloatLike

n_path

Number of points in the path.

Type:

int

n_segments

Number of line segments (n_path - 1).

Type:

int

segment_lengths

Lengths of each straight segment. Not defined for Bezier curves.

Type:

list of FloatLike

path_angles

Angles (radians) each straight segment makes with the positive x-axis. Not defined for Bezier curves.

Type:

list of FloatLike

vertices

Array of vertices defining the arrow polygon.

Type:

ndarray of shape (N, 2)

x_vertices

X-coordinates of the arrow polygon vertices.

Type:

ndarray of FloatLike

y_vertices

Y-coordinates of the arrow polygon vertices.

Type:

ndarray of FloatLike

draw_to_ax(ax, fill_arrow=True)

Draw the arrow on a provided matplotlib Axes object.

Parameters:
  • ax (matplotlib.axes.Axes) – The axes to draw the arrow onto.

  • fill_arrow (bool, optional) – If True, the self.fc attribute will be used to fill the arrow. If False, there will be no fill, just an outline of the arrow. Default is True.

Returns:

The same axes, with the arrow drawn.

Return type:

matplotlib.axes.Axes

save_arrow(name='./arrow.png')

Display the arrow using matplotlib.

Generates a plot of the arrow polygon with specified line and fill colors.

Parameters:

name (str, optional) – Name / path of the resulting png. Default is ‘./arrow.png’.

Return type:

None