Primitives

Primitives provide the drawing API and styling helpers.

Layer 2: Drawing primitives using matplotlib.

plotsmith.primitives.accent_point(ax, x, y, *, label=None, color=None, size=30.0, zorder=3, **kwargs)[source]

Highlight a single point with the accent color.

Optionally add a short text label offset slightly from the point.

Parameters:
  • ax (Axes) – Matplotlib axes to modify.

  • x (float) – X coordinate of the point.

  • y (float) – Y coordinate of the point.

  • label (str | None) – Optional label text.

  • color (str | None) – Optional color override (defaults to accent color).

  • size (float) – Marker size.

  • zorder (int) – Z-order for the marker.

  • **kwargs – Additional arguments passed to ax.scatter().

Return type:

None

plotsmith.primitives.add_range_frame(ax, x_data=None, y_data=None)[source]

Shorten axes spines so they span only the data range.

Parameters:
  • ax (Axes) – Matplotlib axes to adjust.

  • x_data – Optional iterable of x data values.

  • y_data – Optional iterable of y data values.

Return type:

None

plotsmith.primitives.apply_axes_style(ax, spec)[source]

Apply figure specification to axes.

Parameters:
  • ax (Axes) – Matplotlib axes to style.

  • spec (FigureSpec) – FigureSpec containing styling information.

Return type:

None

plotsmith.primitives.direct_label(ax, x, y, text, *, dx=0.0, dy=0.0, use_accent=False, ha='left', va='center', **kwargs)[source]

Place a direct label near a data point.

Typical use is to label the last point of a line instead of using a legend.

Parameters:
  • ax (Axes) – Matplotlib axes to label.

  • x (float) – X coordinate of the point.

  • y (float) – Y coordinate of the point.

  • text (str) – Label text.

  • dx (float) – X offset for label position.

  • dy (float) – Y offset for label position.

  • use_accent (bool) – If True, use accent color.

  • ha (str) – Horizontal alignment.

  • va (str) – Vertical alignment.

  • **kwargs – Additional arguments passed to ax.text().

Return type:

None

plotsmith.primitives.draw_band(ax, view)[source]

Draw a confidence band or shaded region on the given axes.

Parameters:
  • ax (Axes) – Matplotlib axes to draw on.

  • view (BandView) – BandView containing the data to plot.

Return type:

None

plotsmith.primitives.draw_bar(ax, view)[source]

Draw a bar chart on the given axes.

Parameters:
  • ax (Axes) – Matplotlib axes to draw on.

  • view (BarView) – BarView containing the data to plot.

Return type:

None

plotsmith.primitives.draw_heatmap(ax, view)[source]

Draw a heatmap on the given axes.

Parameters:
  • ax (Axes) – Matplotlib axes to draw on.

  • view (HeatmapView) – HeatmapView containing the data to plot.

Return type:

None

plotsmith.primitives.draw_histogram(ax, view)[source]

Draw a histogram on the given axes.

Parameters:
  • ax (Axes) – Matplotlib axes to draw on.

  • view (HistogramView) – HistogramView containing the data to plot.

Return type:

None

plotsmith.primitives.draw_scatter(ax, view)[source]

Draw a scatter plot on the given axes.

Parameters:
  • ax (Axes) – Matplotlib axes to draw on.

  • view (ScatterView) – ScatterView containing the data to plot.

Return type:

None

plotsmith.primitives.draw_series(ax, view)[source]

Draw a time series on the given axes.

Parameters:
  • ax (Axes) – Matplotlib axes to draw on.

  • view (SeriesView) – SeriesView containing the data to plot.

Return type:

None

plotsmith.primitives.emphasize_last(ax, x, y, *, size=30.0, **kwargs)[source]

Emphasize a final point in a series using the accent color.

Parameters:
  • ax (Axes) – Matplotlib axes to modify.

  • x (float) – X coordinate of the point.

  • y (float) – Y coordinate of the point.

  • size (float) – Marker size.

  • **kwargs – Additional arguments passed to ax.scatter().

Return type:

None

plotsmith.primitives.event_line(ax, x, *, text=None, y_text=0.9, color=None, linewidth=1.0, linestyle='--', **kwargs)[source]

Draw a vertical event marker with optional label.

Parameters:
  • ax (Axes) – Matplotlib axes to modify.

  • x (float) – X coordinate for the vertical line.

  • text (str | None) – Optional label text.

  • y_text (float) – Y position for text (0-1 is fraction of y-span, otherwise data coords).

  • color (str | None) – Optional color override (defaults to accent color).

  • linewidth (float) – Line width.

  • linestyle (str) – Line style.

  • **kwargs – Additional arguments passed to ax.axvline().

Return type:

None

plotsmith.primitives.force_bar_zero(ax)[source]

Force bar chart y-axis to start at zero, preserving honest scale.

Parameters:

ax (Axes) – Matplotlib axes to adjust.

Return type:

None

plotsmith.primitives.minimal_axes(ax)[source]

Apply minimalist axes styling.

Removes top and right spines, keeps left and bottom spines. Uses serif font.

Parameters:

ax (Axes) – Matplotlib axes to style.

Return type:

None

plotsmith.primitives.note(ax, x, y, text, **kwargs)[source]

Attach a short note with a simple arrow, avoiding legends.

Parameters:
  • ax (Axes) – Matplotlib axes to annotate.

  • x (float) – X coordinate of the point.

  • y (float) – Y coordinate of the point.

  • text (str) – Note text.

  • **kwargs – Additional arguments passed to ax.annotate().

Return type:

None

plotsmith.primitives.style_bar_plot(ax, *, horizontal=False)[source]

Style bar charts with alternating light fills and clean edges.

Parameters:
  • ax (Axes) – Matplotlib axes to style.

  • horizontal (bool) – If True, style for horizontal bars.

Return type:

None

plotsmith.primitives.style_line_plot(ax, *, emphasize_last=False)[source]

Apply a restrained hierarchy of line styles to an axes.

Parameters:
  • ax (Axes) – Matplotlib axes to style.

  • emphasize_last (bool) – If True, emphasize the last line with thicker width.

Return type:

None

plotsmith.primitives.style_scatter_plot(ax)[source]

Style scatter collections with neutral points.

Parameters:

ax (Axes) – Matplotlib axes to style.

Return type:

None

plotsmith.primitives.tidy_axes(ax)[source]

Clean up axes spines and ticks with minimalist styling.

Removes top and right spines, colors remaining spines gray, and adjusts tick parameters.

Parameters:

ax (Axes) – Matplotlib axes to style.

Return type:

None