Skip to main content

Custom Scatter Plots

Usage and examples for wandb.plot.scatter()
Created on October 5|Last edited on October 6

Method: wandb.plot.scatter()

Log a custom scatter plot—a list of points (x, y) on a pair of arbitrary axes x and y—natively in a few lines:

data = [[x, y] for (x, y) in zip(x_values, y_values)]
table = wandb.Table(data, columns = ["x", "y"])
wandb.log({"my_custom_plot_id" : wandb.plots.scatter(table, "x", "y", title="Custom Y vs X Scatter Plot")

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).

Basic usage example

I finetune a CNN to predict 10 classes of living things: plants, birds, insects, etc. I want to plot the prediction scores for two of my ten classes (on the same batch of examples) against each other to see if there are any patterns. E.g., does the model confuse reptiles and amphibians more often (more correlated scores) than plants and animals (less correlated scores).

I pick two lists of scores (of the same length) and in my validation step I call:

data = [[x, y] for (x, y) in zip(class_x_prediction_scores, class_y_prediction_scores)]
table = wandb.Table(data, columns = ["class_x", "class_y"])
wandb.log({"my_custom_id" : wandb.plots.scatter(table, "class_x", "class_y")})

Steps to follow:

  • create a data object: collect your points as a 2D list/array, where each row is a point and each column is a dimension. This scatter plot assumes two dimensions / two columns, but you could pass in more data and customize the plot further if you wish, e.g. use a third dimension to color the 2D points.
  • pass data to a wandb.Table() object in which you name the columns in order so you can refer to them later
  • pass the table object and the same x and y column names in order to wandb.plots.scatter() with an optional title, which will create your custom plot under the key my_custom_id. To visualize multiple runs on the same plot, keep this plot key constant. Note that the table itself will also be logged in the "Media" section of your workspace, under my_custom_id_table.

The results for a few class correlations are below. You can toggle the points on and off by run name/color via the "eye" icon to the left of each run name.




Class prediction comparisons
5


Customized usage

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

Here are some simple ones:

  • change the appearance and opacity of the point markers: change "mark": {"type": "circle", to "mark": {"type": "point", "opacity" : 0.5,
  • rename the axis titles for clarity: add "title" : "Your Title" to the x and y fields under encoding

On any chart, you can pan around and zoom in to see more detail, as well as see more information about a point on hover (and modify this display information as well!). Try hiding some of the runs below and zooming into the dense region near the origin.




Compare to fungi
3