Plotting an array value

I’ve used the following code to log a metric

wandb.log({"metric": [4, 5, 6]})

but then found out that Wandb doesn’t support plotting a list by default. I want to create a line plot where the y-axis is the first element of the metric array, and the x-axis is the step.

I’ve read the Custom Charts section of the document. I think I should use Vega to access the first element of the array. Here are the steps that I’ve taken:
For the custom chart, I’ve set the data source as “history” and selected the “metric” key.

query {
         (runSets: "${runSets}" ) {
                (keys: ["metric" ] )

In the Vega script, I tried to flatten the array, using this part of the documentation

"transform": {
    {"type": "flatten", "fields": ["${field:metric}"]},

This gives me a warning that “type” and “fields” arguments are not allowed, which means I should include this flattening block somewhere else (not in the transform section).
I’m afraid I don’t know where, and how I can achieve this.
Is this even possible?
If not, I think in my notebook I should write a script that accesses the log data, and transform the data for each run. if so, any tips for that solution are also appreciated.

I’ve also read similar posts in the community, but their use cases were different.

[cross-posted in Stackoverflow, but since I’m a new user, I can’t put its link here (2 URL limit))

I’ve used this code snippet to add the plot for the previous runs. I thought it might help somebody. but still, if there’s a way to do this with Vega, it would be so much better. as this alternate method requires the following code snippet to be run every time we want to see the updated plots.

import matplotlib.pyplot as plt
import wandb

runs = api.runs('workspace/project_name')

for i in range(len(runs))[:1]:
    run_history = runs[i].scan_history(keys=["metric"])
    values = [row['metric'] for row in run_history]

    wandb.log({"metric_plot": plt})

Hello @nialda !

I believe an easier way would be to use our Weave Table. In order for this to work, you must opt into Weave 1.0 (as shown in the following screenshot.

Here is a workspace where I logged 100 steps of wandb.log({"metric": [random.randint(0,100), 5, 6]}) in one run and graphed the x-axis as step and the y-axis as the first item in the list.

Here are the steps to creating the Table:

  1. Press Add Panel → Weave
  2. For the query, write in runs.history.concat. This will make a table of log history.
  3. Go to the bottom right of the panel and select Columns and make sure that only _step and metric is chosen
  4. Press the Gear in the top right of the Panel. This should open up your settings. For the X Dim, write in row["_step"] and for the Y Dim write in row["metric"][0]. This will make a scatterplot. In order to change this to a line plot, change the Mark into a line.

Your resulting Line Graph should look like the image above. I have included the Weave Panel Settings for ease.

Hope this helps!

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.