Skip to content

Offline plot: Invalid value of type 'numpy.int64' received for the 'name' property of scatter3d #1070

@NTNguyen13

Description

@NTNguyen13

I have made a python script to draw a 3D scatter map. Usually I can draw it online by the code:

x = []
y = []
z = []
hover = []
trace = {}
layout = {}

#creating trace
for i in range(len(np.unique(y_le))):
    name = np.unique(y_random)[i]
    # color = range(len(X_tsne['Name'].unique))[i]
    color = c[i]
    x = X_tsne[y_random == name][:, 0]
    y = X_tsne[y_random == name][:, 1]
    z = X_tsne[y_random == name][:, 2]
    hover = filename_random[y_random == name]

    trace = dict(
        name=name,
        x=x, y=y, z=z,
        type="scatter3d",
        mode='markers',
        # colorscale='Viridis'
        text=hover,
        marker=dict(size=2, color=color, line=dict(width=0)))
    data.append(trace)

#creating fig
layout = dict(
    width=1600,
    height=1200,
    autosize=False,
    title='t-SNE embedding - hover',
    scene=dict(
        xaxis=dict(
            gridcolor='rgb(255, 255, 255)',
            zerolinecolor='rgb(255, 255, 255)',
            showbackground=True,
            backgroundcolor='rgb(230, 230,230)'
        ),
        yaxis=dict(
            gridcolor='rgb(255, 255, 255)',
            zerolinecolor='rgb(255, 255, 255)',
            showbackground=True,
            backgroundcolor='rgb(230, 230,230)'
        ),
        zaxis=dict(
            gridcolor='rgb(255, 255, 255)',
            zerolinecolor='rgb(255, 255, 255)',
            showbackground=True,
            backgroundcolor='rgb(230, 230,230)'
        ),
        aspectratio=dict(x=1, y=1, z=0.7),
        aspectmode='manual'
    ),
)

fig = dict(data=data, layout=layout)
url = py.plot(fig, filename='tSNE embedding')

However, when I tried to draw them offline by this:
plotly.offline.plot(fig)

it raises the error
ValueError:
Invalid value of type 'numpy.int64' received for the 'name' property of scatter3d
Received value: 0
The 'name' property is a string and must be specified as:
- A string
- A number that will be converted to a string

I tried to replace the line name = name in making trace by using name = '%d' % name but it still the same error

How can I draw offline plot by plotly in this case?

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