notcurses_plot(3)
β¨ notcurses_plot β high level widget for plotting β¨
okay so this is the notcurses_plot(3) page from the notcurses fam, and bestie, it's giving data visualization but make it terminal π
like literally plotting histograms inside your TUI. buckle up π
πΈ SYNOPSIS πΈ
#include <notcurses/notcurses.h>
the little flag besties, all six of them, yes we're listing every single one π:
#define NCPLOT_OPTION_LABELTICKSD 0x0001u
#define NCPLOT_OPTION_EXPONENTIALD 0x0002u
#define NCPLOT_OPTION_VERTICALI 0x0004u
#define NCPLOT_OPTION_NODEGRADE 0x0008u
#define NCPLOT_OPTION_DETECTMAXONLY 0x0010u
#define NCPLOT_OPTION_PRINTSAMPLE 0x0020u
and here's the options struct, the icon itself π«Ά:
typedef struct ncplot_options {
// channels for the maximum and minimum levels.
// lerp across the domain between these two.
uint64_t maxchannels;
uint64_t minchannels;
// styling used for labels (NCPLOT_OPTION_LABELTICKSD)
uint16_t legendstyle;
// pass NCBLIT_DEFAULT maps to NCBLIT_8x1 (assuming
// UTF8) or NCBLIT_1x1 (in an ASCII environment)
ncblitter_e gridtype;
// independent variable can either be a contiguous range,
// or a finite set of keys. for a time range, say the
// previous hour sampled with second resolution, the
// independent variable would be the range [0..3600): 3600.
// if rangex is 0, it is dynamically set to the number
// of columns.
int rangex;
const char* title; // optional title
uint64_t flags; // bitfield over NCPLOT_OPTION_*
} ncplot_options;
and the functions, every last one, no skips π:
struct ncuplot* ncuplot_create(struct ncplane* n, const ncplot_options*
opts, uint64_t miny, uint64_t maxy);
struct ncdplot* ncdplot_create(struct ncplane* n, const ncplot_options*
opts, double miny, double maxy);
struct ncplane* ncuplot_plane(struct ncuplot* n);
struct ncplane* ncdplot_plane(struct ncdplot* n);
int ncuplot_add_sample(struct ncuplot* n, uint64_t x, uint64_t y);
int ncdplot_add_sample(struct ncuplot* n, uint64_t x, double y);
int ncuplot_set_sample(struct ncuplot* n, uint64_t x, uint64_t y);
int ncdplot_set_sample(struct ncuplot* n, uint64_t x, double y);
int ncuplot_sample(const struct ncuplot* n, uint64_t x, uint64_t* y);
int ncdplot_sample(const struct ncdplot* n, uint64_t x, double* y);
void ncuplot_destroy(struct ncuplot* n);
void ncdplot_destroy(struct ncdplot* n);
π¦ DESCRIPTION π¦
so these functions support histograms β yes, actual histograms, in your terminal, slay π₯ the independent variable is always a uint64_t. the samples are either uint64_ts (that's ncuplot) or doubles (that's ncdplot). only a window over the samples is retained at any given time, and here's the tea: this window can only move towards larger values of the independent variable. it moves forward whenever an x larger than the current window's maximum is handed to add_sample or set_sample β
add_sampleincrements the current value corresponding to thisxbyy.set_samplereplaces the current value corresponding to thisx.
if rangex is 0, or larger than the bound plane will support, it gets capped to the available space (rude but fair π). the domain can either be specified as miny and maxy, or domain autodetection can be invoked by setting both to 0. if the domain is specified, samples outside the domain are an error and do not contribute to the plot. supplying an x below the current window is an error too, and has no effect π
more granular block glyphs means more resolution in your plots, but ngl they can be difficult to differentiate at small text sizes. octants, sextants, and Braille allow for more resolution on the independent variable. it can be difficult to predict how the Braille glyphs will look in a given font β font-dependent chaos, iykyk π
the same ncplot_options struct can be used with all ncplot types, one struct to rule them all π
the flags field is a bitmask composed of:
NCPLOT_OPTION_LABELTICKSDβ Label dependent axis ticksNCPLOT_OPTION_EXPONENTIALDβ Use an exponential dependent axisNCPLOT_OPTION_VERTICALIβ Vertical independent axisNCPLOT_OPTION_NODEGRADEβ Fail rather than degrade blitterNCPLOT_OPTION_DETECTMAXONLYβ Detect only max domain, not minNCPLOT_OPTION_PRINTSAMPLEβ Print the most recent sample
if NCPLOT_OPTION_LABELTICKSD or NCPLOT_OPTION_PRINTSAMPLE is supplied, the legendstyle field will be used to style the labels. otherwise it's literally ignored, main character of nothing π
the label is printed in the upper left, immediately to the right of the topmost axis tick (if NCPLOT_OPTION_LABELTICKSD was used). the most recent sample is printed opposite from the label along the independent axis (if NCPLOT_OPTION_PRINTSAMPLE was used). positioned, periodt β¨
π NOTES π
NCPLOT_OPTION_VERTICALI is not yet implemented. like it exists, it's in the bitmask, but it does not do the thing yet π don't come for me, I'm just the messenger π
π RETURN VALUES π
create will return an error if miny equals maxy, but they are non-zero. it will also return an error if maxy < miny. and an invalid gridtype will result in an error too β bestie the validation is not playing around π«Ά
plane returns the ncplane on which the plot is drawn. it cannot fail. iconic. flawless. no notes π
π SEE ALSO π
notcurses(3), notcurses_plane(3), notcurses_visual(3)
π AUTHORS π
nick black nickblack@linux.com
and that's the whole page bestie, mwah π this lil beauty is v3.0.17 of the notcurses_plot(3) manual β go plot something iconic and remember: respect the window, it only moves forward π β¨
π¦ where this page comes from
- alpine 3.24: notcurses-doc 3.0.17-r0 Β· Apache-2.0
- ubuntu resolute: libnotcurses-core-dev 3.0.17+dfsg-3 Β· Apache-2.0
- ubuntu stonking: libnotcurses-core-dev 3.0.17+dfsg-3 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms