API reference¶
The package exposes a function and an artist class. Use the curved_text
function for the common case. Use the CurvedText class when you need to keep a
reference to the label and change it after drawing.
- curved_text.curved_text(ax: Axes, x: ArrayLike, y: ArrayLike, text: str, *, pos: float = 0.5, anchor: str = 'center', offset: float = 0.0, box: bool | str | dict = False, **kwargs: Any) CurvedText[source]¶
Draw
textalong the curve(x, y)onaxand return the artist.Thin convenience wrapper around
CurvedText; see it for the meaning ofpos,anchor,offset, andbox. The axes is the first argument here, matching matplotlib’s axes-first helper functions, whereasCurvedTexttakes it afterx, y, textto matchmatplotlib.text.Text.
- class curved_text.CurvedText(x: ArrayLike, y: ArrayLike, text: str, axes: Axes, *, pos: float = 0.5, anchor: str = 'center', offset: float = 0.0, box: bool | str | dict = False, **kwargs: Any)[source]¶
Bases:
TextA string drawn along an (x, y) curve, one character at a time.
Each character is an independent
matplotlib.text.Text, centered (ha="center",va="center") on its own arc-length midpoint, placed in display coordinates and rotated to the chord across its own advance – the direction from where the glyph starts on the curve to where it ends. The chord follows the local tangent but averages over the glyph’s own width, so rotation stays smooth across the vertices of a coarsely sampled polyline instead of snapping to each segment’s angle. The layout is recomputed on every draw, so the label keeps following the curve through figure layout, resizing, and interactive panning or zooming.Placement has three independent controls:
posWhere the label is anchored along the curve, as a fraction of the curve’s arc length:
0.0is the first point,1.0is the last.anchorWhich part of the label lands at
pos:"start","center", or"end".offsetA perpendicular shift off the curve, in typographic points, along the normal of the label’s chord (the line from its first to its last glyph). Positive is to the left of the direction of travel, which is visually above a left-to-right curve.
A label that overruns either end of the curve – because of
posandanchor– is not clipped. The curve is extended along its end tangent and the overrunning glyphs are placed on that straight extension.Set
boxto draw a casing behind the label – a band that follows the curve at the label’s height, drawn under the glyphs – so the label stays legible where it crosses the lines it labels. For a lighter, glyph-hugging casing instead, pass a whitewithStrokethroughpath_effects; a wide stroke there merges adjacent per-character glyphs, soboxis the way to get solid coverage under plain text.Mathtext is supported: each
$...$run intextis laid out by matplotlib’s mathtext engine and bent continuously along the curve – every glyph outline and rule box is mapped through the curve’s arc-length frame, so radicals, fractions, and sized delimiters stay connected at any curvature. Passparse_math=Falseto treat dollar signs literally.text.usetexis not supported. Tall expressions compress vertically on the inside of tight bends, so choose label size relative to curvature accordingly.- Parameters:
x (array-like) – The curve in data coordinates: 1-D, equal length, at least two points, finite, and ordered along the curve.
y (array-like) – The curve in data coordinates: 1-D, equal length, at least two points, finite, and ordered along the curve.
text (str) – The string to draw. May contain mathtext runs (
$...$).axes (matplotlib.axes.Axes) – The axes to draw into.
pos (float, default 0.5) – Arc-length fraction in
[0, 1]for the anchor point.anchor ({"start", "center", "end"}, default "center") – Which part of the label sits at
pos.offset (float, default 0.0) – Perpendicular offset off the curve, in points.
box (bool, str, or dict, default False) – A casing drawn behind the label to clear the lines it crosses.
Truedraws a white band; a color string sets its color; a dict acceptscolor,pad(band height relative to the tallest glyph, default1.1), andalpha.**kwargs – Passed to each per-character
Textand each mathtext run (for examplecolor,fontsize,alpha,fontfamily).
- set_zorder(zorder) None[source]¶
Set the zorder for the artist. Artists with lower zorder values are drawn first.
- Parameters:
level (float)
- remove() None[source]¶
Remove the artist from the figure if possible.
The effect will not be visible until the figure is redrawn, e.g., with .FigureCanvasBase.draw_idle. Call ~.axes.Axes.relim to update the Axes limits if desired.
Note: there is no support for removing the artist’s legend entry.
- draw(renderer, *args, **kwargs) None[source]¶
Draw the Artist (and its children) using the given renderer.
This has no effect if the artist is not visible (.Artist.get_visible returns False).
- Parameters:
renderer (~matplotlib.backend_bases.RendererBase subclass.)
Notes
This method is overridden in the Artist subclasses.