Colorbar in plotly scatter3d

Hi

I’m having difficulty making the colorbar appear in plotly scatterplot 3d.

In the code sample below I can get the colorbar to appear if I set:

color = 'z'

However if I choose to use:

color = flowers["petal_length"]

it wont appear although the data are the same and the resulting cooring of the data points is the same.

Am I missing something obvious?

import holoviews as hv
from holoviews import opts

from bokeh.sampledata.iris import flowers

hv.extension("plotly")


def hook(plot, element):

    plot.handles["components"]["traces"][0]["marker"]["line"] = dict(
        width=10, color="black"
    )


flower_plot = hv.Scatter3D(
    (flowers["sepal_length"], flowers["sepal_width"], flowers["petal_length"])
).opts(
    opts.Scatter3D(
        # color = 'z',
        color=flowers["petal_length"],
        alpha=0.7,
        size=5,
        cmap="Portland",
        marker="circle",
        hooks=[hook],
    )
)

flower_plot.opts(width=800, height=800, colorbar=True)

Hi, did you find a fix for this problem? I’m facing the same problem now and I can’t really find a solution

Hi Rajunm

Unfortunately, I wasn’t able to fix this.

I have it working using the colorbar=True option. Please see below. Hope this is helpful.

opts(cmap='rainbow', colorbar=True, height=1600, width=1200)
1 Like

This works

import holoviews as hv
from holoviews import opts

from bokeh.sampledata.iris import flowers

hv.extension("plotly")


def hook(plot, element):

    plot.handles["components"]["traces"][0]["marker"]["line"] = dict(
        width=10, color="black"
    )

data = flowers.rename(
    columns=dict(sepal_length="x", sepal_width="y", petal_length="z")
)

flower_plot = hv.Scatter3D(
    data
).opts(
    color="z",
    alpha=0.7,
    size=5,
    cmap="Portland",
    colorbar=True,
    marker="circle",
    hooks=[hook],
    xlabel="Sepal Length",
    ylabel="Sepal Width",
    zlabel="Petal Length",
)

plot = flower_plot.opts(width=800, height=800)
plot

But I think Scatter3D or its documentation is not working well, so I created an issue here

1 Like

Thanks @Marc

Yes I can reproduce your work however the issue is the labelling of the colorbar legend with the string: “im(‘z’”. I had hoped that this this colorbar string value could be set by the user (potentially to reflect a meaning value like the name of the dimension it represents).

One thing I haven’t tried is to extract the Holoviz object out into a plotly object and try and configure it there with that.

In any case it’s a minor issue.

I think 3d scatter plots are underrated ( mindful if the visualisation rule 101 of not plotting quantitate data in 3D ) since they present the opportunity for a “bird’s eye view” to appreciate potential clustering and anomalies. I’m hoping Plotly will some day present the capability to select a user defining subset of points in the 3D scatter plot with say a plane (from square / rectangular selection) followed by extrusion orthogonally. A point project to sphere or disc to cylinder might be interesting candidates also.

2 Likes

Hi @Cerioscha

A fix of the color bar title is included in #5418

3 Likes

Thanks @Marc !!