'Setting hoverdistance with plotly for 3D scatterplot

    #point_size = 10
    pca_dims   = 3
    title_wrap = 40

    data = self.vectorize(df["excerpt"].tolist())

    # Dimensionality reduction (3 principal components).
    pca = PCA(n_components = pca_dims)
    pca.fit(data)
    new_values = pca.transform(data)

    # Create new columns to store new dimensional values.
    df.loc[:,"x"]    = new_values[:,0]
    df.loc[:,"y"]    = new_values[:,1]
    df.loc[:,"z"]    = new_values[:,2]
    df.loc[:,"size"] = 1

    # Create extra column for formatted title in hover text.
    df.loc[:,"title_format"] = df["title"].str.wrap(title_wrap).apply(
                                    lambda x : x.replace('\n', '<br>'))

    fig = px.scatter_3d(df, x = "x", y = "y", z = "z",
        color = "keyword", size = 'size', size_max = 30, hover_name = "title_format",
        hover_data  = {"size" : False, "keyword" : False, "x" : False, "y" : False, "z" : False},
        labels      = {"keyword" : "Search Keywords"},
        custom_data = ["excerpt", "title", "id"],
    )
    fig.update_layout(hovermode='closest', hoverdistance=1000)

So essentially the issue here is that neither the size or hoverdistance fields are behaving as I would expect. For example, (this is there just because I was trying to figure out what was setting the size) the size gets set to 1, which is below the max size of 30, so I would expect the output dots on the plot to have size 1, except they dont, and have size 30...

The hoverdistance is behaving in a very similar way, I want to set it such that the hoverdistance is 0, so that the hover will only activate when the cursor overlaps with at least a pixel of a point. However it was never working, so I set it to a crazy high number, 1000 as seen above, and it exhibited the same behavior. So, it seems like the plotly graph is (for seemingly only the size and hoverdistance fields as everything else looks as expected) taking default values for certain fields despite them being specified otherwise.

I also tried having and not having the "hovermode='closest'", since its set to closest by default, just wanted to test it had any affect. Also the point_size variable is currently unused since I set the size directly to 1 when trying to debug the issue.

I'm somewhat at a loss for why this is happening as the code is essentially the same as the example given in the documentation by plotly. The main documentation page I used is linked below:

Plotly reference

Thanks



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source