Skip to content

plotly.io.read_json 5.x doesn't work for graphs created with plotly>=6 #5297

@StageTired

Description

@StageTired

Steps to reproduce:

  1. create an environemnt with plotly==6.2.0 + numpy
  2. run this code (purely random plot), note the write_json at the end
import numpy as np

# Generate random data
np.random.seed(42) # for reproducibility
random_x = np.random.rand(100) * 10 # 100 random numbers between 0 and 10
random_y = np.random.rand(100) * 10 # 100 random numbers between 0 and 10

# Create a scatter trace
scatter_trace = go.Scatter(
    x=random_x,
    y=random_y,
    mode='markers', # Display markers for each data point
    marker=dict(size=8, color='blue', opacity=0.7) # Customize marker appearance
)

# Create a Figure object and add the trace
fig = go.Figure(data=[scatter_trace])

# Update layout (optional)
fig.update_layout(
    title='Random Scatter Plot (go.Figure)',
    xaxis_title='X-axis',
    yaxis_title='Y-axis'
)

# Display the plot
fig.show()

fig.write_json("test1.json")
  1. create a second environment with plotly<6.0.0 (5.9.0 in my example).
  2. run this code
from plotly.io import read_json

content = read_json("test1.json")
# content = read_json("test1.json", skip_invalid="True")

content.show()
  1. observe the next error:
    Invalid value of type 'builtins.dict' received for the 'x' property of scatter
        Received value: {'dtype': 'f8', 'bdata': 'Zyb35ZT2DUD0ZXVBqAMjQCUB5jKeRx1A3Pf7S0PyF0DlqeoEhvb4Px/f/xmJ9fg/ZrVeojWW4j/RktVl0lIhQJjetu9qCxhAIiNBx6lSHEAgngaJIFnKP0cUzj3wZSNAeqzYNxumIEBf/gF6tPwAQIYf2PeMF/0/WoFZrD9Y/T8C1R2S4VYIQHwLCYCB/RRAGIUd8x1HEUBSbD9vX0wHQHHS/6ZfeRhAm+3uJKtR9j9p0LxVH18HQAblUy4XTw1A6vlzGSg+EkC6iBesM2gfQJE0pluj8v8/GInqucKRFEDddFU/U7IXQEyUy4Rvut0/LMtmYEJNGEBhjgIJq0j7P0jVh8gG0eQ/VgJbQEv6IkAkgeg3CVAjQKOqdpL+KiBApN8ocH1eCEBMWjyxTEHvPzmDNNOLXhtAypNqWimbEUDOLjOkr4bzP099Ko+czhNAAILeHTcC1j9fR/pvuC8iQDyG0mPQswRA1NzGajqAGkAmZkDE1+8IQFIqCh1/zRRAC6jWMVDeFUDzUqB0o5P9P/APm/ZFZCNAbq8/MFwBH0Bq5XwNPMoiQMkP0RqE5SFAfOii637qF0Bw/FD//m8iQKZY0UZOUew/36tqQnVb/z+IzeT8CfLcP7QBcuLDBgpAtCN5YxwYD0CgnGVpOrUFQFCF99MikyBAuA2n4U6KDED1ARLsiXkGQGlHYTg1tRVAmuvsmUGM9j9WxWmgPwsgQOIdoFAw2+c/GfoOcty8I0DGcvlTyeMeQNKo3vFky/8/ANYCCfNFrD9WQn+aKU8gQIiEjh04RhxAuGzzjAgpHUD2oAfwztkeQCZSDeW8sec/1sGCzGCtDEDwl0wm/4nyP1IGIOwWQyFA/0s/pJLuGED4P/SiyngKQMYt1TazVuQ/zDuw/urgCEDewqgiwQMKQHTc9NEqLx1A1qRfqJaAGUAfMmd8h74hQHol6hd74xJAdipvj5Qi8z8UnD5qoIccQFTQm1twbh5AiQ8uf3pzFkB4xEc0tNYeQEfBM4d3wBNABKaNv8joFEC08I0gBRoRQIScJXOrRNA/Ys0InDtD8T8='}

    The 'x' property is an array that may be specified as a tuple,
    list, numpy array, or pandas Series

Basically, figures saved with Plotly 6.x are not read back correctly when using Plotly 5.x. I am not if this is how it's supposed to be or not.
If I try content = read_json("test1.json", skip_invalid="True") it doesn't produce an error but the plot is completely wrong.
I would love any feedback on this, thanks in advance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions