Log Plots
Log informative charts throughout training, including precision-recall and ROC curves and custom charts
Using the methods in `wandb.plot`, you can track charts with `wandb.log`, including charts that change over time during training. To learn more about our custom charting framework, check out this guide.

## Basic Charts

These simple charts make it easy to construct basic visualizations of metrics and results.
Line
Scatter
Bar
Histogram
Multi-line
`wandb.plot.line()`
Log a custom line plot—a list of connected and ordered points on arbitrary axes.
1
data = [[x, y] for (x, y) in zip(x_values, y_values)]
2
table = wandb.Table(data=data, columns = ["x", "y"])
3
wandb.log({"my_custom_plot_id" : wandb.plot.line(table, "x", "y",
4
title="Custom Y vs X Line Plot")})
Copied!
You can use this to log curves on any two dimensions. Note that if you're plotting two lists of values against each other, the number of values in the lists must match exactly (i.e. each point must have an x and a y). `wandb.plot.scatter()`
Log a custom scatter plot—a list of points (x, y) on a pair of arbitrary axes x and y.
1
data = [[x, y] for (x, y) in zip(class_x_scores, class_y_scores)]
2
table = wandb.Table(data=data, columns = ["class_x", "class_y"])
3
wandb.log({"my_custom_id" : wandb.plot.scatter(table,
4
"class_x", "class_y")})
Copied!
You can use this to log scatter points on any two dimensions. Note that if you're plotting two lists of values against each other, the number of values in the lists must match exactly (i.e. each point must have an x and a y). `wandb.plot.bar()`
Log a custom bar chart—a list of labeled values as bars—natively in a few lines:
1
data = [[label, val] for (label, val) in zip(labels, values)]
2
table = wandb.Table(data=data, columns = ["label", "value"])
3
wandb.log({"my_bar_chart_id" : wandb.plot.bar(table, "label",
4
"value", title="Custom Bar Chart")
Copied!
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). `wandb.plot.histogram()`
Log a custom histogram—sort a list of values into bins by count/frequency of occurrence—natively in a few lines. Let's say I have a list of prediction confidence scores (`scores`) and want to visualize their distribution:
1
data = [[s] for s in scores]
2
table = wandb.Table(data=data, columns=["scores"])
3
wandb.log({'my_histogram': wandb.plot.histogram(table, "scores",
4
title="Histogram")})
Copied!
You can use this to log arbitrary histograms. Note that `data` is a list of lists, intended to support a 2D array of rows and columns. `wandb.plot.line_series()`
Plot multiple lines, or multiple different lists of x-y coordinate pairs, on one shared set of x-y axes:
1
wandb.log({"my_custom_id" : wandb.plot.line_series(
2
xs=[0, 1, 2, 3, 4],
3
ys=[[10, 20, 30, 40, 50], [0.5, 11, 72, 3, 41]],
4
keys=["metric Y", "metric Z"],
5
title="Two Random Metrics",
6
xname="x units")})
Copied!
Note that the number of x and y points must match exactly. You can supply one list of x values to match multiple lists of y values, or a separate list of x values for each list of y values. ## Model Evaluation Charts

These preset charts have built-in `wandb.plot` methods that make it quick and easy to log charts directly from your script and see the exact information you're looking for in the UI.
Precision-Recall Curves
ROC Curves
Confusion Matrix
`wandb.plot.pr_curve()`
Create a Precision-Recall curve in one line:
1
wandb.log({"pr": wandb.plot.pr_curve(ground_truth, predictions)})
Copied!
• a model's predicted scores (`predictions`) on a set of examples
• the corresponding ground truth labels (`ground_truth`) for those examples
• (optionally) a list of the labels/class names (`labels=["cat", "dog", "bird"...]` if label index 0 means cat, 1 = dog, 2 = bird, etc.)
• (optionally) a subset (still in list format) of the labels to visualize in the plot `wandb.plot.roc_curve()`
Create an ROC curve in one line:
1
wandb.log({"roc": wandb.plot.roc_curve(ground_truth, predictions)})
Copied!
• a model's predicted scores (`predictions`) on a set of examples
• the corresponding ground truth labels (`ground_truth`) for those examples
• (optionally) a list of the labels/ class names (`labels=["cat", "dog", "bird"...]` if label index 0 means cat, 1 = dog, 2 = bird, etc.)
• (optionally) a subset (still in list format) of these labels to visualize on the plot `wandb.plot.confusion_matrix()`
Create a multi-class confusion matrix in one line:
1
cm = wandb.plot.confusion_matrix(
2
y_true=ground_truth,
3
preds=predictions,
4
class_names=class_names)
5
6
wandb.log({"conf_mat": cm})
Copied!
• a model's predicted labels on a set of examples (`preds`) or the normalized probability scores (`probs`). The probabilities must have the shape (number of examples, number of classes). You can supply either probabilities or predictions but not both.
• the corresponding ground truth labels for those examples (`y_true`)
• a full list of the labels/class names as strings (`class_names`, e.g. `class_names=["cat", "dog", "bird"]` if index 0 is cat, 1=dog, 2=bird, etc) ## Interactive Custom Charts

For full customization, tweak a built-in Custom Chart preset or create a new preset, then save the chart. Use the chart ID to log data to that custom preset directly from your script.
1
# Create a table with the columns to plot
2
table = wandb.Table(data=data,
3
columns=["step", "height"])
4
5
# Map from the table's columns to the chart's fields
6
fields = {"x": "step",
7
"value": "height"}
8
9
# Use the table to populate the new custom chart preset
10
# To use your own saved chart preset, change the vega_spec_name
11
my_custom_chart = wandb.plot_table(
12
vega_spec_name="carey/new_chart",
13
data_table=table,
14
fields=fields)
Copied!

## Matplotlib and Plotly Plots

Instead of using W&B Custom Charts with `wandb.plot`, you can log charts generated with matplotlib and Plotly.
1
import matplotlib.pyplot as plt
2
3
plt.plot([1, 2, 3, 4])
4
plt.ylabel("some interesting numbers")
5
wandb.log({"chart": plt})
Copied!
Just pass a `matplotlib` plot or figure object to `wandb.log()`. By default we'll convert the plot into a Plotly plot. If you'd rather log the plot as an image, you can pass the plot into `wandb.Image`. We also accept Plotly charts directly.
If you’re getting an error “You attempted to log an empty plot” then you can store the figure separately from the plot with `fig = plt.figure()` and then log `fig` in your call to `wandb.log`.