Logging list of wandb.Plotly not working

Hi, I am trying to log multiple connected plots similar to using images, as shown in the documentation:

examples = []
for i in range(3):
 pixels = np.random.randint(low=0, high=256, size=(100, 100, 3))
 image = wandb.Image(pixels, caption=f"random field {i}")
 examples.append(image)
wandb.log({"examples": examples})

Trying this with wandb.Plotly instead of wandb.Image:

plots = []
for i in range(3):
 fig = create_plotly_plot(index=i)
 plot = wandb.Plotly(fig)
 plots.append(plot)
wandb.log({"examples": plots})

results in an error in the UI:

Selected runs are not logging media for the key examples, but instead are logging values of type list.

If examples is never supposed to be a media type, please delete this panel and create the proper panel type manually.

How can I log a list of plots similar to a list of images?

Hi @mbp thanks for writing in! Would it work for you to add a slider instead for your Plotly figures as follows:

import plotly.graph_objects as go
import numpy as np

for i in range(3):
    x = np.linspace(0, 10, 100)
    y = np.sin(x) + np.random.normal(0, 0.1, 100)
    fig = go.Figure(data=go.Scatter(x=x, y=y))
    plot = wandb.Plotly(fig)
    wandb.log({"examples_2": plot}, step = i)

Another alternative would be to convert the Plotly to html and add them in a wandb.Table, for example:

# Create a table
table = wandb.Table(columns = ["plotly_figure"])
for i in range(3):
    x = np.linspace(0, 10, 100)
    y = np.sin(x) + np.random.normal(0, 0.1, 100)
    fig = go.Figure(data=go.Scatter(x=x, y=y))

    # Create path for Plotly figure
    path_to_plotly_html = "./plotly_figure.html"
    # Write Plotly figure to HTML
    fig.write_html(path_to_plotly_html, auto_play = False) 
    # Add Plotly figure as HTML file into Table
    table.add_data(wandb.Html(path_to_plotly_html))

wandb.log({"examples_3": table})

Would any of these options work for your use case?

1 Like

Thank you for your reply. When doing it this way the plots do not show up in the UI at all, unfortunately. I can see them in the files section unter root/media/plotly but they cannot be added to the charts section.

By chance, I tried to log the plots one by one without the step=i part and then they showed up in the charts section with a slider. Could you clarify if that is the intended way to do it maybe?

Thank you!

Hi @mbp thanks for the update, could you please try to Add Panel > Plotly and then add in media keys the key you had used to log the plots (for instance in the code snippet above that would be examples_2). Would this work for you?

Hi @thanos-wandb, thanks for your reply. I’m sorry that I did not mention it explicitly but I have tried to add it manually before and the problem is, that the key does not exist in the backend. Here is an excerpt from my code:

_fs = self.log_pred_probs(
     y_train_pred_prob, y_test_pred_prob, threshold=0.5, n_plots=20
)
for i, _f in enumerate(_fs):
     _pf = wandb.Plotly(_f)
     run.log({"prediction_probabilities": _pf}, step=i)

And the files in the files section:

But when adding a plot, the media key does not exist:

Manually specifying the key does not work at all.

Hi @mbp thanks for the additional details, this shouldn’t be the expected behaviour. Are you logging in our SaaS (wandb.ai) or in a local W&B instance? If the former could you please send us a link to your Workspace (or email it to support@wandb.com in case you don’t want to publicly share), or in the latter case please provide us with your Local/Server version (found from <host-url>/settings page).

Hi @thanos-wandb, it is a local setup (Docker) and the version from /settings is

W&B Local 0.30.0

However, this was tested with 0.29.0 as I have since upgraded the version.

Hi @mbp thanks for the additional details, that’s important to know you’re on a self-hosted instance. I have tested it as well though in a 0.30.0 deployment and it worked for me. Could you please try the following code again (in a completely new project)?

import wandb

import plotly.graph_objects as go
import numpy as np

wandb.init(project='plotly')

for i in range(3):
    x = np.linspace(0, 10, 100)
    y = np.sin(x) + np.random.normal(0, 0.1, 100)
    fig = go.Figure(data=go.Scatter(x=x, y=y))
    plot = wandb.Plotly(fig)
    wandb.log({"examples_2": plot}, step = i)

wandb.finish()

Please let me know if this still won’t work for you. I will then try to reproduce if the issue occurs because you logged the data in 0.29.0 and then you upgraded to 0.30.0.