Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

colorbar not showing for Scatter3D and documentation not helpful in any way #5416

Open
MarcSkovMadsen opened this issue Sep 3, 2022 · 2 comments
Labels
type: bug Something isn't correct or isn't working
Milestone

Comments

@MarcSkovMadsen
Copy link
Collaborator

MarcSkovMadsen commented Sep 3, 2022

I am trying to help a user add a colorbar to his Scatter3D plot https://discourse.holoviz.org/t/colorbar-in-plotly-scatter3d/1864

But it does not work

Original Bug

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)

image

Try to get it working

Ok so I can see a bug report having a working colorbar #4952. So I figure maybe the issue is that specifying individual series for x, y and z dimensions is not working. Instead I should provide the dataframe and then specify which columns to use for what?

But how to do this is not documented in the reference example or docstring

image

Maybe I would know if I am a super user of HoloViews. But it is not a fair requirement that users should be that. Using the docstring in combination with the reference guide should be enough for non-advanced use cases. It should take a few minutes at most to get a working example not 3 hours of studying a tutorial/ guide, looking at discourse and looking at github.

So my option now is to study a bug report on Github !!!! in the hope to figure out how this works.

After studying that example I get something working

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

image

But I'm left with the feeling that this cannot really be the solution (renaming columns to x, y, z), I've not learned anything and it works for this use case but probably a little tweak on the use case will raise new questions.

Solution

Either fix bug if this is a bug or add a meaningful, working example of this use case to the reference documentation.

@MarcSkovMadsen MarcSkovMadsen added the type: bug Something isn't correct or isn't working label Sep 3, 2022
@MarcSkovMadsen MarcSkovMadsen added this to the 1.15.1 milestone Sep 3, 2022
@MarcSkovMadsen
Copy link
Collaborator Author

MarcSkovMadsen commented Sep 3, 2022

Ok, so after studing the code of Scatter3D I can see x,y,z should be kdims. This is not documented in an easy to find place like docstring or reference documentation. Its not obvious as for a 2D Scatter x is a kdim and y is a vdim. If I should have guessed, I would have guessed x,y were kdim and z was vdim. Making them all kdim is a mistake I believe. It makes HoloViews unintuitive.

import holoviews as hv
from bokeh.sampledata.iris import flowers

hv.extension("plotly")

hv.Scatter3D(
    flowers, kdims=["sepal_length", "sepal_width", "petal_length"]
).opts(
    color="petal_width",
    alpha=0.7,
    size=5,
    cmap="Portland",
    colorbar=True,
    marker="circle",
)

@droumis
Copy link
Member

droumis commented Jul 12, 2023

Can we close this issue since the original issue was resolved in #5418 and showing of docstring in hv.help output is in #5421? @MarcSkovMadsen, if you want to bring up the issue of "Making them all kdim is a mistake".. I think that's best done in a new issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't correct or isn't working
Projects
None yet
Development

No branches or pull requests

3 participants