ComfyUI Node

Plot

The node that turns spectra into line charts you can actually see

By chenlongming·Created 2 years ago·Updated 2 years ago· 2
Plot
  • image
  • series
  • image

Numbers are hard to look at. A row of mean-spectrum values - say, 220 numbers for 220 bands - tells you nothing at a glance, but draw them as a line and suddenly you can see where a vegetation class dips in the visible range and climbs in the near-infrared. That's the whole job of the Plot node: take the NDARRAY of spectra your analysis produced and render it as a matplotlib chart, as a normal ComfyUI IMAGE you can view, save, or pipe anywhere.

It's the visualization end of this pack's pipeline, and it's the node that makes the previous steps legible.

How it works

Give it a spectral image plus a series array. It takes the number of bands from the image to build the x-axis - x = arange(nbands) - then plots every row of series as its own curve on one set of axes. The figure is saved to temp/plot.png via matplotlib, loaded back as an image tensor, and returned as an IMAGE. One chart, one run, every spectrum overlaid on the same band axis so you can compare them directly.

It's deliberately dumb, which is the right call. No normalization, no legends worth the name, no interactive fiddling - just the curves, which is what you actually want when you're comparing class spectra.

Inputs

  • image (SPE) - the spectral object. Slightly surprising, but the node never looks at the actual pixel data; it only uses image.nbands to size the x-axis. Any SPE output from either loader works.
  • series (NDARRAY) - the spectra to plot, one per row. The intended source is the Calculate node's results output (mean spectra per mask/class), and the pack's KMeans node also outputs cluster-center spectra as an NDARRAY that feeds straight in. It'll happily plot any row-based array you hand it.

Output

image (IMAGE) - the rendered chart. Wire it to a PreviewImage to see it, or a Save Image node to keep it. Since it's a normal image, you could even run it through ComfyUI's image ops, though I can't imagine why you'd want to.

Installing it

ComfyUI Manager: search ComfyUI_Spectral, install, restart. Or:

cd ComfyUI/custom_nodes
git clone https://github.com/chenlongming/ComfyUI_Spectral
cd ComfyUI_Spectral
pip install -r requirements.txt

then restart. (requirements.txt - the README spells it reqirements.txt.) The dependency you're most likely missing is spectral; matplotlib usually shows up somewhere in a ComfyUI env, but the pack lists it too. No model downloads.

The gotchas

A real one, straight from the source: Plot does not create the temp/ directory itself. The loaders call os.makedirs('temp') when they run, and Plot assumes it already exists when it does fig.savefig('temp/plot.png'). In practice you can't reach Plot without an SPE input, and every SPE comes from a loader, so the directory exists by the time you execute - but it's a fragile assumption, and if you ever see a FileNotFoundError on a plot that "should work," that's why. It also overwrites the same temp/plot.png every run, so concurrent runs can clobber each other; keep graph executions serial.

And a caveat about expectations rather than mechanics: this is matplotlib with its default styling, saved at whatever default DPI it lands on. Your chart will be functional, not publication-grade. If you need a beautiful figure, do what you'd do in Python anyway - reproduce the math in a notebook and style it there. This node is for seeing results inside ComfyUI, not for the paper.

Like the rest of this early-stage pack, it's thin and the README warns the API may change. But as the payoff node - the one that turns the pack's boring mean-spectra arrays into something your eyes can compare - it does exactly what it needs to.

CategorySpectral

Inputs (2)

NameTypeDefaultDescription
imageSPE
seriesNDARRAY

Outputs (1)

NameTypeDescription
imageIMAGE