Skip to content

Tutorial plotly.figure_factory create_dendrogram() not working resulting in AttributeError #4495

Closed
@Snirpsi

Description

@Snirpsi

Hi,
when i run the tutorial from the website https://plotly.com/python/dendrogram/ the program crashes.

I put the code in a test.py file in a complete new venv.

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

X = np.random.rand(15, 12) # 15 samples, with 12 dimensions each
fig = ff.create_dendrogram(X)
fig.update_layout(width=800, height=500)
fig.show()

Error:

Traceback (most recent call last):
  File "/home/snirps/Documents/GitHub/testproject/.venv/lib/python3.11/site-packages/scipy/__init__.py", line 137, in __getattr__
    return globals()[name]
           ~~~~~~~~~^^^^^^
KeyError: 'array'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/snirps/Documents/GitHub/testproject/test.py", line 6, in <module>
    fig = ff.create_dendrogram(X)
          ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/snirps/Documents/GitHub/testproject/.venv/lib/python3.11/site-packages/plotly/figure_factory/_dendrogram.py", line 94, in create_dendrogram
    dendrogram = _Dendrogram(
                 ^^^^^^^^^^^^
  File "/home/snirps/Documents/GitHub/testproject/.venv/lib/python3.11/site-packages/plotly/figure_factory/_dendrogram.py", line 148, in __init__
    (dd_traces, xvals, yvals, ordered_labels, leaves) = self.get_dendrogram_traces(
                                                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/snirps/Documents/GitHub/testproject/.venv/lib/python3.11/site-packages/plotly/figure_factory/_dendrogram.py", line 346, in get_dendrogram_traces
    icoord = scp.array(P["icoord"])
             ^^^^^^^^^
  File "/home/snirps/Documents/GitHub/testproject/.venv/lib/python3.11/site-packages/scipy/__init__.py", line 139, in __getattr__
    raise AttributeError(
AttributeError: Module 'scipy' has no attribute 'array'

I have the following packages installed with pip.

pip==23.2
pipdeptree==2.13.2
plotly==5.18.0
├── packaging [required: Any, installed: 23.2]
└── tenacity [required: >=6.2.0, installed: 8.2.3]
scipy==1.12.0
└── numpy [required: >=1.22.4,<1.29.0, installed: 1.26.3]
setuptools==68.1.2

python:

Python 3.11.6

Thanks for your great work.

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