Skip to content

Error when running the create_dendrogram example #2618

Closed
@soungalo

Description

@soungalo

I am running plotly.py version 4.8.2 in a jupyter notebook.
I ran the following code, copied from the documentation page:

import plotly.figure_factory as ff
import numpy as np
np.random.seed(1)

X = np.random.rand(10,10)
fig = ff.create_dendrogram(X)
fig.update_layout(width=800, height=500)
fig.show()

and getting the following error message:

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-1-386e391a19fb> in <module>
      4 
      5 X = np.random.rand(10,10)
----> 6 fig = ff.create_dendrogram(X)
      7 fig.update_layout(width=800, height=500)
      8 fig.show()

~/miniconda3/envs/jupyterlab_new/lib/python3.8/site-packages/plotly/figure_factory/_dendrogram.py in create_dendrogram(X, orientation, labels, colorscale, distfun, linkagefun, hovertext, color_threshold)
     89         distfun = scs.distance.pdist
     90 
---> 91     dendrogram = _Dendrogram(
     92         X,
     93         orientation,

~/miniconda3/envs/jupyterlab_new/lib/python3.8/site-packages/plotly/figure_factory/_dendrogram.py in __init__(self, X, orientation, labels, colorscale, width, height, xaxis, yaxis, distfun, linkagefun, hovertext, color_threshold)
    143             distfun = scs.distance.pdist
    144 
--> 145         (dd_traces, xvals, yvals, ordered_labels, leaves) = self.get_dendrogram_traces(
    146             X, colorscale, distfun, linkagefun, hovertext, color_threshold
    147         )

~/miniconda3/envs/jupyterlab_new/lib/python3.8/site-packages/plotly/figure_factory/_dendrogram.py in get_dendrogram_traces(self, X, colorscale, distfun, linkagefun, hovertext, color_threshold)
    335                 y=np.multiply(self.sign[self.yaxis], ys),
    336                 mode="lines",
--> 337                 marker=dict(color=colors[color_key]),
    338                 text=hovertext_label,
    339                 hoverinfo="text",

KeyError: 'C1'

I've tried downgrading to 4.8.1, but got the same error.
My working env is created with miniconda3, using the yml file:

name: jupyterlab_new
channels:
  - conda-forge
  - bioconda
dependencies:
  - jupyterlab
  - pandas
  - numpy
  - seaborn
  - plotly
  - biopython

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugsomething broken

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions