Custom Bar Charts

Usage and examples for Made by Stacey Svetlichnaya using Weights & Biases
Stacey Svetlichnaya


Log a custom bar chart—a list of labeled values as bars—natively in a few lines:

data = [[label, val] for (label, val) in zip(labels, values)]
table = wandb.Table(data=data, columns = ["label", "value"])
wandb.log({"my_bar_chart_id" :, "label", "value",
                               title="Custom Bar Chart")})

You can use this to log arbitrary bar charts. Note that the number of labels and values in the lists must match exactly (i.e. each data point must have both). In the example below, you can display/hide individual runs from the bar chart by clicking on the "eye" icon to the left of each run name under "Toy CNN variants".

You can also see more information about a bar on hover (and modify this through the Vega spec in your charts!). To see the full Vega spec of a chart, hover over the top right corner and click on the "eye" icon.

Basic usage

I finetune a CNN to predict 10 classes of living things: plants, birds, insects, etc. I want to plot the final precision for each label in my validation step. I compute the precision using sklearn.metrics.precision_score. This returns val_precision, a list of 10 precision values, one for each class. I then create a bar for each label:

data = [[name, prec] for (name, prec) in zip(self.class_names, val_precision)]
table = wandb.Table(data=data, columns=["class_name", "precision"])
wandb.log({"my_bar_chart_id" :, "class_name",
           "precision", title="Per Class Precision")})

Steps to follow:

Customized usage

There are many ways to customize the line plot using the Vega visualization grammar.

Here are some simple ones:

See the full API for →.

P.S. Computing per class precision for multi-class models

You can compute this whenever your code has access to:

from sklearn.metrics import precision_score

ground_truth_class_ids = ground_truth.argmax(axis=1)
guessed_class_ids = val_predictions.argmax(axis=1)
val_precision = precision_score(ground_truth_class_ids,
                guessed_class_ids, average=None)

# now you can log val_precision to a custom chart!