Tensorboard
Data Visualization
Custom Plots
Machine Learning
Tutorial

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.

Practice ML system design

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.

python
1import tensorflow as tf
2
3logdir = "logs/custom"
4writer = tf.summary.create_file_writer(logdir)
5
6for step in range(5):
7    value = step * step
8    with writer.as_default():
9        tf.summary.scalar("quadratic", value, step=step)
10
11writer.flush()

After that, start TensorBoard with:

bash
tensorboard --logdir logs/custom

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:

python
1import math
2import tensorflow as tf
3
4writer = tf.summary.create_file_writer("logs/scalars")
5
6for step in range(50):
7    with writer.as_default():
8        tf.summary.scalar("sin", math.sin(step / 10), step=step)
9        tf.summary.scalar("cos", math.cos(step / 10), step=step)
10
11writer.flush()

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.

python
1import io
2import matplotlib.pyplot as plt
3import numpy as np
4import tensorflow as tf
5
6
7def figure_to_image(figure):
8    buffer = io.BytesIO()
9    figure.savefig(buffer, format="png")
10    plt.close(figure)
11    buffer.seek(0)
12    image = tf.image.decode_png(buffer.getvalue(), channels=4)
13    return tf.expand_dims(image, 0)
14
15writer = tf.summary.create_file_writer("logs/images")
16
17x = np.linspace(0, 2 * np.pi, 100)
18y = np.sin(x)
19
20fig, ax = plt.subplots()
21ax.plot(x, y)
22ax.set_title("Custom sine plot")
23
24with writer.as_default():
25    tf.summary.image("sine_plot", figure_to_image(fig), step=0)
26
27writer.flush()

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/f1 or debug/queue_size
  • separate scalar and image logs only when it improves navigation

For example:

python
1from datetime import datetime
2import tensorflow as tf
3
4run_id = datetime.now().strftime("%Y%m%d-%H%M%S")
5writer = tf.summary.create_file_writer(f"logs/experiment/{run_id}")

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_writer as 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
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track 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.

Practice ML system design

All Rights Reserved.