Recreating wandb plots with matplotlib/seaborn

I have been using w&b for a few months and have had a great experience with it. However, I have had some trouble with including the diagram in my report. Under *more actions > export panel … * there exist options for exporting the panel to PNG, SVG, PDF, and CSV. I want to export the panel to PDF with vectorized graphics and text but the PDF export seems to simply render the panel to PNG.

What I have tried:

  • exporting to SVG, but I was not able to convert this format to pdf or any other format suitable for my LaTeX report. I have been unable to use SVG files in my LaTeX report directly.
  • creating a report of the panel and downloading the report as LaTeX, but again it renders the plots as PNG which is not desired in my case.

Perhaps I am missing something, but as a final resort I have tried recreating the plots in wandb with the Export API in the following code snippet:

import wandb
import pandas as pd 
import seaborn as sns
import matplotlib.pyplot as plt

api = wandb.Api()

# Project is specified by <entity/project-name>
runs = api.runs("<wandb-id>/<entity-project-name>")
hist_list = [] 
for run in runs: 
    if not 'val/loss' in run.summary:
        continue

    name = run.config['model']['_target_'].split('.')[-1]
    hist = run.history(keys=['epoch', 'val/loss'])
    hist['name'] = name
    hist_list.append(hist)

df = pd.concat(hist_list, ignore_index=True)
df = df.query("`val/loss` != 'NaN'")

sns.lineplot(x="epoch", y="val/loss", hue="name", data=df)
plt.show()

The script takes a long time to run (10 seconds) and comparing the output with the panel in the w&b dashboard we have the following two plots

The two plots have a noticeable difference. So I have two questions:

  • Is it possible to export a panel to pdf with selectable text?
  • If not, is there any reference for recreating the plots in wandb?

Any help is appreciated :slight_smile:

EDIT

I found a github thread that explains my problem a bit better: Custom Charts: Export Panel Feature · Issue #1446 · wandb/client · GitHub

Hi @kevjn, thank you for writing in and I’m glad you’re enjoying our product!

Currently there isn’t a way to export the panel with selectable text but I can put in a feature request around this if you would like? It sounds like this would solve most of your issues. I believe the issue here was the way that Vega wants to render charts but I can talk to our engineering team and see if there is a way around this.

I don’t have any specific references for recreating plots in Python but are you using custom charts? If so, you can access the Vega code that was used to create the chart in the UI and use that locally to recreate the chart.

Thank you,
Nate

Hi @nathank, I am not using custom charts - the charts are rendered by default in the dashboard. Where can I access the Vega code and data used to populate the charts?

I did get around my issue by exporting to CSV and doing some acrobatics with pandas and matplotlib, but I would prefer an easier way of doing it.

@kevjn Unfortunately, only the custom charts are created with Vega and our standard charts are actually written in Javascript.

I think using your acrobatics to make Matplotlib work will be the best workaround for now. I’ve put in the feature request for exporting text- selectable PDF and can follow up with you if we are able to implement this feature.

I apologize that I don’t have a better workaround for you in the meantime.

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