Plot custom data with Tensorboard
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.
Introduction
TensorBoard is not limited to training loss and accuracy. If you have custom experiment data, you can log it through the TensorFlow summary APIs and view it as scalars, images, histograms, or text. The right summary type depends on what your custom data actually is: a numeric time series, a rendered chart, or richer structured output.
The Basic TensorBoard Logging Pattern
In TensorFlow 2, the standard entry point is a summary writer created with tf.summary.create_file_writer. Once the writer is active, you log values with APIs such as tf.summary.scalar or tf.summary.image.
After that, start TensorBoard with:
This is the simplest way to plot custom numeric data over time.
Use Scalars For Numeric Series
If your custom data is already a sequence of numbers, use scalar summaries. This is the best fit for:
- evaluation metrics
- learning rates
- custom reward signals
- latency measurements
- any one-number-per-step value
Example with two custom series:
TensorBoard's time-series dashboard is built exactly for this pattern.
If You Want A Real Plot, Log It As An Image
Sometimes the custom data is not a single scalar. You might want a scatter plot, confusion matrix, or a hand-built Matplotlib chart. In that case, render the figure to an image and log it with tf.summary.image.
This is the standard solution when people say they want to "plot custom data in TensorBoard." TensorBoard is not a general plotting library by itself, but it can display images of plots very effectively.
Choosing Between Scalars And Images
Use a scalar summary when the data is naturally one value per step. Use an image summary when the visualization itself carries the meaning.
Examples:
- custom validation score: scalar
- confusion matrix heatmap: image
- ROC curve figure: image
- batch-level gradient norm: scalar
That distinction keeps your logs compact and your dashboards readable.
Organize Runs And Tags Carefully
TensorBoard becomes hard to navigate when runs and tags are messy. A useful pattern is:
- one log directory per experiment run
- clear tag names such as
eval/f1ordebug/queue_size - separate scalar and image logs only when it improves navigation
For example:
This makes comparison across runs much easier.
Logging Outside Model Training
TensorBoard does not require a Keras training loop. You can log from any Python script as long as you write event files. That makes it useful for simulation pipelines, evaluation scripts, reinforcement learning experiments, and data-processing jobs.
The important requirement is simple: write summaries with a valid step value when the data is time-ordered.
Common Pitfalls
- Logging a full chart as many scalars when one image would communicate the result more clearly.
- Forgetting
writer.flush(), then wondering why TensorBoard does not show recent data. - Writing all experiments into one directory without distinct run names.
- Using image summaries for simple numeric series, which makes comparison harder than using scalars.
- Mixing steps inconsistently across tags so plots do not align meaningfully.
Summary
- Use
tf.summary.create_file_writeras the entry point for custom TensorBoard logging. - Log numeric time-series data with
tf.summary.scalar. - Log rendered charts or visual diagnostics with
tf.summary.image. - Keep run directories and tag names organized so TensorBoard stays readable.
- TensorBoard works well for custom scripts, not just Keras model training.
Related reading
- Plot multiple graphs in one plot using Tensorboard
- Plotting learning curve in keras gives KeyError 'val_acc
- Poetry fails to install tensorflow
- Poor results with tensorflow DNNClassifier and cross_val_score
- Plot decision tree in R Caret
- Plot feature importance with xgboost
- Plot Interactive Decision Tree in Jupyter Notebook
- Plot k-Nearest-Neighbor graph with 8 features?
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.