draw#
Drawing planar diagrams using Matplotlib.
This module renders planar diagrams given a geometric layout. It draws arcs/segments, endpoints (with gaps at undercrossings), vertices, orientation arrows, and optional labels.
Notes#
Layouts are expected to be produced by knotpy.drawing.layout_circle_packing.
Elements in the layout are instances of CircularArc or Segment.
A small gap is rendered at underpassing endpoints of crossings to visualize over/under information.
- draw(k, ax=None, rotation=0.0, arc_color='tab:blue', arc_width=4.0, arc_style='solid', arc_alpha=None, arc_stroke_color='white', arc_stroke_width=None, arc_stroke_alpha=None, gap=0.1, cmap=None, vertex_color='black', vertex_size=0.15, vertex_alpha=None, vertex_stroke_color='black', vertex_stroke_width=0, vertex_stroke_alpha=None, arrow_color=None, arrow_width=0.15, arrow_length=0.12, arrow_style='open', arrow_cap_style='round', arrow_position='middle', arrow_alpha=None, label_endpoints=False, label_arcs=False, label_nodes=False, label_color='black', label_font_size=14, label_font_family='serif', label_horizontal_alignment='left', label_vertical_alignment='top', label_alpha=None, title=(False,), title_color='black', title_font_size=(16,), title_font_family='serif', title_alpha=None, show_circle_packing=False, padding_fraction=0.05, show_axis=False, show=True)#
High-level convenience function to draw a diagram.
- This function:
Adds support arcs (to eliminate bridges etc.) for robust drawing,
Decomposes the diagram into disjoint components,
Computes a circle-packing layout for each component,
Aligns components horizontally,
Renders the composed result to Matplotlib.
- Parameters:
k (Diagram) – The diagram to draw.
**kwds – Optional keyword arguments: - ax: Matplotlib axes to draw on. If omitted, a new figure/axes is created. - with_labels (bool): If True, draw node/endpoint/arc labels. Default False. - show (bool): If True, call plt.show() at the end. Default False.
- draw_from_layout(k, layout, ax=None, arc_color='tab:blue', arc_width=4.0, arc_style='solid', arc_alpha=None, arc_stroke_color='white', arc_stroke_width=None, arc_stroke_alpha=None, gap=0.1, cmap=None, vertex_color='black', vertex_size=0.15, vertex_alpha=None, vertex_stroke_color='black', vertex_stroke_width=0, vertex_stroke_alpha=None, arrow_color=None, arrow_width=0.15, arrow_length=0.12, arrow_style='open', arrow_cap_style='round', arrow_position='middle', arrow_alpha=None, label_endpoints=False, label_arcs=False, label_nodes=False, label_color='black', label_font_size=14, label_font_family='serif', label_horizontal_alignment='left', label_vertical_alignment='top', label_alpha=None, title=(False,), title_color='black', title_font_size=(16,), title_font_family='serif', title_alpha=None, padding_fraction=0.05, show_axis=False, show=True)#
Render a diagram from a precomputed layout onto given axes.
- Parameters:
k (Diagram) – Diagram to draw.
layout (dict) – Mapping of arcs/endpoints/nodes to geometric elements or positions.
ax – Matplotlib axes to draw on.
with_labels (bool) – If True, draw node/endpoint/arc labels.