Custom Multi-Line Plots

Usage and examples for wandb.plot.line_series(). Made by Stacey Svetlichnaya using Weights & Biases
Stacey Svetlichnaya

Method: wandb.plot.line_series()

Log a custom line series plot natively in W&B:
wandb.log({"my_custom_id" : wandb.plot.line_series( xs=[0, 1, 2, 3, 4], ys=[[10, 20, 30, 40, 50], [0.5, 11, 72, 3, 41]], keys=["metric Y", "metric Z"], title="Two Random Metrics", xname="x units")})
This Custom Chart renders multiple lines, or multiple different lists of x-y coordinate pairs, on one shared set of x-y axes. Two examples with default settings and random data are below. You can pan via click+drag and zoom via scroll in these charts to see small details (e.g. lines that are too close together to distinguish).

Basic usage example

I follow a TensorFlow tutorial on time series with a weather dataset of 14 different features like temperature, pressure, and humidity. A small subset of the full data is loaded into a Pandas dataframe called climate_data.
columns = ['T (degC)', 'p (mbar)', 'rho (g/m**3)']num_steps = 200xs = [ i for i in range(num_steps) ]ys= [ climate_data[c][:num_steps] for c in columns ]wandb.log({"weather_sample" : wandb.plot.line_series( xs=xs, ys=ys, keys=columns, title="Weather Metrics")})
Note that the number of x and y points must match exactly. You can supply one list of xs to match multiple lists of ys, or a separate list of xs for each ys list. If these air temperature/pressure/density measurements were taken at different times, we could supply three different lists of x values. See the full definition of the line series plot here.

Steps to follow:

Customized usage

It's easy to customize the line series plot using the Vega visualization grammar. Here I compare multiple time slices on the same set of axes to better visualize the variance in the data. You can see the full Vega spec (definition for each chart) by hovering over the top right corner of the chart and clicking the "eye" icon.
Some simple changes:

More examples: Logging different x values

In the simple case, multiple lists of y-values will be mapped to a single list of x-values. Here I sample three vapor pressure metrics at different frequencies to show a slightly more advanced case: passing a list of x-values corresponding to each list of y-values. I also change "type" : "line" to "type" : "point" to clearly distinguish the x-values.
In the bottom row of charts, you can compare the visualization effectiveness/perceptual grouping strength when coloring data by sample id (bottom left) versus by metric type (bottom right).

How to edit a preset to make your own custom chart

Modified Vega spec

This version of the lineseries spec colors lines by metric instead of by run and contains specific titles.
{ "$schema": "https://vega.github.io/schema/vega-lite/v4.json", "description": "A plot for an arbitrary number of lines", "data": { "name": "wandb" }, "title": "Climate Data Sample", "layer": [ { "selection": { "grid": { "type": "interval", "bind": "scales" } }, "mark": {"type": "line", "interpolate": "linear"}, "encoding": { "x":{ "field": "${field:step}", "type": "quantitative", "title": "Time step of measure" }, "y": { "field": "${field:lineVal}", "title": "Value in indicated units", "type": "quantitative" }, "color": { "type": "nominal", "field": "${field:lineKey}", "title" : "Units of measure" }, "strokeDash": { "type": "nominal", "field": "name", "title" : "Sample id" } } } ]}

Q & A

Thanks for reading! We hope this helps you build unique and compelling custom charts. Please comment below with any questions!