Tensorboard
Data Visualization
Multiple Graphs
Plotting
Python

Plot multiple graphs in one plot using 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 can show multiple curves together, but the exact behavior depends on how you log the data. Sometimes you want multiple runs overlaid for the same metric, and sometimes you want different scalar metrics grouped into one chart. Those are related but different use cases.

Same Tag Across Different Runs

The simplest way to compare multiple curves in one TensorBoard scalar chart is to log the same tag name in different run directories.

python
1import tensorflow as tf
2
3for run_name, values in {
4    "run_a": [0.9, 0.7, 0.5],
5    "run_b": [1.0, 0.8, 0.6],
6}.items():
7    writer = tf.summary.create_file_writer(f"logs/{run_name}")
8    with writer.as_default():
9        for step, loss in enumerate(values):
10            tf.summary.scalar("loss", loss, step=step)

When you launch TensorBoard on logs, both runs appear on the same scalar card for loss, letting you compare them directly.

That is the easiest answer when the curves represent the same metric from different experiments.

Multiple Metrics From One Run

If you log different scalar tags such as train_loss and val_loss, TensorBoard will normally show separate scalar cards.

python
1import tensorflow as tf
2
3writer = tf.summary.create_file_writer("logs/single_run")
4with writer.as_default():
5    for step in range(3):
6        tf.summary.scalar("train_loss", 1.0 - 0.2 * step, step=step)
7        tf.summary.scalar("val_loss", 1.1 - 0.15 * step, step=step)

This is useful, but it is not yet "one plot." For that, you usually want the Custom Scalars plugin.

Use Custom Scalars to Group Curves in One Chart

TensorBoard supports custom scalar layouts so related metrics can be displayed together in one multiline chart.

python
1import tensorflow as tf
2from tensorboard.plugins.custom_scalar import layout_pb2
3from tensorboard.plugins.custom_scalar import summary as cs_summary
4
5writer = tf.summary.create_file_writer("logs/custom_scalars")
6
7layout = layout_pb2.Layout(category=[
8    layout_pb2.Category(
9        title="Losses",
10        chart=[
11            layout_pb2.Chart(
12                title="Train vs Validation Loss",
13                multiline=layout_pb2.MultilineChartContent(
14                    tag=["train_loss", "val_loss"]
15                ),
16            )
17        ],
18    )
19])
20
21with writer.as_default():
22    tf.summary.experimental.write_raw_pb(
23        cs_summary.pb(layout).SerializeToString(), step=0
24    )
25    for step in range(3):
26        tf.summary.scalar("train_loss", 1.0 - 0.2 * step, step=step)
27        tf.summary.scalar("val_loss", 1.1 - 0.15 * step, step=step)

Now TensorBoard can render both series in a single multiline chart in the Custom Scalars dashboard.

Naming Conventions Help Even Without Custom Layouts

Even when you do not use the Custom Scalars plugin, consistent naming makes TensorBoard easier to navigate.

Examples:

  • 'loss/train'
  • 'loss/val'
  • 'accuracy/train'
  • 'accuracy/val'

This keeps related metrics grouped logically in the UI and makes it easier to filter or compare runs.

Choose the Right Comparison Mode

A useful rule is:

  • Same metric across experiments: use the same tag in different run directories.
  • Different but related metrics in one experiment: use separate scalar tags and optionally group them with Custom Scalars.

This distinction prevents a lot of confusion when people try to force every charting problem into one TensorBoard feature.

Common Pitfalls

  • Logging different experiments into the same run directory and mixing the data accidentally.
  • Expecting different scalar tags to appear on one chart automatically without a custom layout.
  • Using inconsistent tag names, which makes TensorBoard harder to read than it needs to be.
  • Comparing runs with different preprocessing or training conditions as if the curves were directly equivalent.
  • Forgetting that the Scalars and Custom Scalars dashboards solve slightly different visualization problems.

Summary

  • TensorBoard overlays curves automatically when different runs log the same scalar tag.
  • Different metrics from the same run normally appear as separate scalar cards.
  • Use the Custom Scalars plugin when you want multiple scalar series in one multiline chart.
  • Keep run directories and tag names organized so the comparisons stay interpretable.
  • Decide first whether you are comparing multiple runs or multiple metrics, because the logging strategy differs.

Related reading
Course
Intermediate
27 lessons
15 hours
DSA Fundamentals

Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.

View the 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.