ComfyUI Node

NNT Plot Tensors

Turn numbers into a picture you can actually read

By inventorado·Created 2 years ago·Updated 2 years ago· 69
NNT Plot Tensors
  • x_tensor
  • y_tensor
  • y_tensor2
  • IMAGE
plot_typescatter
x_labelX Value
y_labelY Value
plot_width800
plot_height600
use_linesFalse
y2_labelY2 Value

Tensors are great until you're staring at 10,000 numbers and wondering what they mean. NNT Plot Tensors is the toolkit's graph-paper node: give it an x tensor and a y tensor, and it renders a matplotlib chart and hands it back as a ComfyUI IMAGE you can preview, save, or display in your workflow. For an educational pack, this is quietly one of the most useful nodes - it's how you see your loss curve, your predictions vs. targets, or your data distribution instead of squinting at a text dump.

What it actually does

It flattens both input tensors to 1D (so they must have the same number of elements - that's the one hard requirement), then draws whichever plot_type you picked. line connects points in order, scatter plots them as points, line_and_scatter does both, and connected_scatter is a scatter with optional connecting lines (toggled by use_lines). The figure is rendered at your chosen plot_width/plot_height (in pixels, defaults 800×600), saved to a PNG in memory, and converted back to a [1, H, W, 3] image tensor in 0–1 range - so it plugs straight into ComfyUI's image preview node.

Inputs that matter

  • x_tensor / y_tensor - the two data series. Flattened internally, so 2D tensors work as long as their element counts match.
  • plot_type - line, scatter, line_and_scatter, or connected_scatter. For a training loss curve, line; for predictions vs. labels, scatter (or line_and_scatter if there's a clear order).
  • x_label / y_label - axis labels; set these so the chart isn't a mystery to future you.
  • plot_width / plot_height - figure size in pixels.

Two optional inputs round it out: y_tensor2 lets you overlay a second series on the same axes, with its own y2_label - the natural move for comparing train loss vs. validation loss in one plot.

Gotchas

The element-count mismatch is the classic failure: if len(x) != len(y) you get a clean error message, which beats the alternative of a silently misaligned plot. The tensors are detached and moved to CPU before plotting, so you can feed training tensors that still carry gradients without the plot erroring - nice touch for a teaching tool. One thing it won't do: it's not a line-chart generator in the abstract - it plots the exact points you feed it in order, so "smooth curve" behavior depends on the data being sorted the way you want it. Feed it epoch-by-epoch losses in order and you'll get a proper curve.

Installing NNT

Part of inventorado/ComfyUI_NNT. ComfyUI Manager (search "ComfyUI Neural Network Toolkit") or:

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

Restart ComfyUI after. It needs matplotlib (in the requirements), part of a heavy stack that also includes torch, scikit-learn, pandas, and shap - so the first install is slow. The pack's example workflows use ComfyUI-Jjk-Nodes for text display and lean on nodes like this for visual feedback; let Manager fetch the missing ones.

CategoryNNT Neural Network Toolkit/Visualization

Inputs (10)

NameTypeDefaultDescription
x_tensorTENSOR
y_tensorTENSOR
plot_typeCOMBOscatter4 options: line, scatter, line_and_scatter, connected_scatter
x_labelSTRINGX Value
y_labelSTRINGY Value
plot_widthINT800200–2000
plot_heightINT600200–2000
use_linesCOMBOFalse2 options: True, False
y_tensor2optTENSOR
y2_labeloptSTRINGY2 Value

Outputs (1)

NameTypeDescription
IMAGEIMAGE