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

ValueError in Interactive Plot: [tooltip text] must be of same length as the number of nodes #98

Open
KevinHooah opened this issue Mar 14, 2024 · 6 comments

Comments

@KevinHooah
Copy link

Hello,

When I am going to plot the interactive figure (the static figure works fine), I get the following errors:

ValueError                                Traceback (most recent call last)
[<ipython-input-20-bda0a8197673>](https://localhost:8080/#) in <cell line: 1>()
----> 1 bn.plot(model2_update, title = 'DAG for SJV', interactive=True)

2 frames
[/usr/local/lib/python3.10/dist-packages/bnlearn/bnlearn.py](https://localhost:8080/#) in plot(model, pos, scale, interactive, title, node_color, node_size, node_properties, edge_properties, params_interactive, params_static, verbose)
   1096         print("number of node: ", len(nodelist), "number of tip", len(tooltip))
   1097         # Make interactive plot
-> 1098         fig = _plot_interactive(params_interactive,
   1099                                 nodelist,
   1100                                 node_colors,

[/usr/local/lib/python3.10/dist-packages/bnlearn/bnlearn.py](https://localhost:8080/#) in _plot_interactive(params_interactive, nodelist, node_colors, node_sizes, edgelist, edge_colors, edge_weights, title, tooltip, verbose)
   1204     _, IB = ismember([*d3.D3graph.node_properties.keys()], nodelist)
   1205 
-> 1206     d3.D3graph.set_node_properties(tooltip=np.array(tooltip)[IB],
   1207                                    size=np.array(node_sizes)[IB],
   1208                                    color=np.array(node_colors)[IB],

[/usr/local/lib/python3.10/dist-packages/d3graph/d3graph.py](https://localhost:8080/#) in set_node_properties(self, label, marker, tooltip, color, opacity, size, edge_color, edge_size, fontcolor, fontsize, cmap, scaler, minmax)
    449         else:
    450             tooltip = np.array([''] * nodecount)
--> 451         if len(tooltip) != nodecount: raise ValueError("[tooltip text] must be of same length as the number of nodes")

    452 
    453         # ############ Set node color #############

ValueError: [tooltip text] must be of same length as the number of nodes

I check the number of node and the number of tip in the bnlearn.py's plot function, before it calls fig = _plot_interactive, the number of nodes equals the number of tip.

I also get these output before the error pops out, incase it is helpful:

[d3blocks] >INFO> Cleaning edge_properties and config parameters..
[d3blocks] >INFO> Converting source-target into adjacency matrix..
[d3blocks] >INFO> Making the matrix symmetric..
[d3blocks] >INFO> Set directed=True to see the markers!
[d3blocks] >INFO> Keep only edges with weight>0
[d3blocks] >INFO> Converting source-target into adjacency matrix..
[d3blocks] >INFO> Making the matrix symmetric..
[d3blocks] >INFO> Converting adjacency matrix into source-target..
[d3blocks] >INFO> Number of unique nodes: 6
[d3blocks] >INFO> Slider range is set to [0, 10]
[d3blocks] >INFO> Write to path: [/tmp/tmpyfm91v_7/d3graph.html]
[d3blocks] >INFO> File already exists and will be overwritten: [/tmp/tmpyfm91v_7/d3graph.html]
[bnlearn] >Set node properties.
[bnlearn]> Set edge weights based on the [chi_square] test statistic.
[bnlearn] >Converting source-target into adjacency matrix..
[bnlearn] >Making the matrix symmetric..
[bnlearn] >Set edge properties.
[d3blocks] >INFO> Keep only edges with weight>0
[d3blocks] >INFO> Converting source-target into adjacency matrix..
[d3blocks] >INFO> Making the matrix symmetric..

Thank you for your help in advance.

@erdogant
Copy link
Owner

Thank you for mentioning this. I fixed this issue before.
Can you force update to the latest version of bnlearn and d3blocks?

pip install -U bnlearn
pip install -U d3blocks

I created a new release of bnlearn where I included d3blocks with a minimum version of 1.4.9

@mich415
Copy link

mich415 commented Mar 25, 2024

I'm seeing the same issue (same output as original post) even though it appears I have the latest versions of bnlearn (0.8.5) and d3blocks (1.4.9). Do you have any idea why the issue may persist?

@erdogant
Copy link
Owner

mmm. I need more information. Which python version are u using and does it brake also in toy examples?

@mich415
Copy link

mich415 commented Mar 25, 2024

python version is 3.12.2, and the examples for the interactive plots in the docs do work.

@erdogant
Copy link
Owner

Can you shown an example with data where it does not work

@erdogant
Copy link
Owner

Do you maybe have not-unique node names?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants