Question on using ax.vspan when plotting

Hi!

Does wandb plotting support the use of matplotlib’s axvspan? I’m trying to shade an area and it works locally, but it doesn’t pop up in my plot in wandb.

    fig, ax = plt.subplots()
    ax.plot(x_train, y_train, 'ro', label='data')

    if len(x_test) > 0:
        ax.plot(x_test, y_test, 'bo', label='unseen data')
        ax.axvspan(np.min(x_test), np.max(x_test), alpha=0.3, color='blue')
    wandb.log({"plot": plt})

Thanks,
Andrei

HI @inwaves could you share a link to your workspace?

This may be a bug. We should support it if it is part of the Matplotlib library. I’ll try to reproduce as well.

@inwaves I was able to test and replicate this issue. I’ll report this as a bug and follow up if we are able to create a solution.

1 Like

Hey @nathank, thanks for replicating! Until the solution arrives, using Plotly directly seems to work just fine, something like:

fig.add_vrect(x0=np.min(x_test), x1=np.max(x_test), line_width=0, fillcolor="red", opacity=0.2)

Hi @inwaves, I’m glad that using Plotly directly is working.

I was looking through our source code and we simply call Plotly’s conversion tool here. I tested converting a Matplotlib plot to Plotly with this tool locally and saw that same behavior. Unfortunately, it looks like the change would actually have to take place in the Plotly repo in order for this to work properly.

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