dendrograms / astrodendro

Generate a dendrogram from a dataset
https://dendrograms.readthedocs.io/
Other
37 stars 36 forks source link

Standard astro dendro tree plot is getting error: "TypeError: 'int' object is not subscriptable" #159

Open battersbot opened 6 years ago

battersbot commented 6 years ago

I keep getting the error "TypeError: 'int' object is not subscriptable" when trying to plot a dendrogram tree. I have done this successfully before, and only today am having this issue. So, I attempted the example code from: http://dendrograms.readthedocs.io/en/stable/plotting.html#making-plots-for-publications to be sure, and indeed I get the same error.

Example code from the website and the error is appended below as a screenshot screen shot 2018-02-05 at 5 24 14 pm

astrofrog commented 6 years ago

It looks like the issue is that the subtree option of plot_tree is not passed on to get_lines. I need to investigate when that change was introduced.

battersbot commented 6 years ago

I also just remembered having another issue with .plot_tree previously (issue #157) for which @keflavich suggested I use the developer version, which I did, so maybe this error is only in the developer version?

battersbot commented 6 years ago

@astrofrog @keflavich Any thoughts? Better to switch back to the non-developer version?

Thank you!

AstroJLo commented 6 years ago

I'm currently using version 0.2.0 of astrodendro and i'm also experiencing the same issue as @battersbot . Is there by any chance an update on this issue?

rgalvanmadrid commented 5 years ago

I am getting the same error.

Te version I am using is: In [28]: print(astrodendro.version) 0.2.0

In [29]: p.plot_tree(ax, structure=7, color='red')


TypeError Traceback (most recent call last)

in () ----> 1 p.plot_tree(ax, structure=7, color='red') ~/anaconda3/lib/python3.6/site-packages/astrodendro/plot.py in plot_tree(self, ax, structure, subtree, autoscale, **kwargs) 101 102 # Get the lines for the dendrogram --> 103 lines = self.get_lines(structures=structure, **kwargs) 104 105 # Add the lines to the axes ~/anaconda3/lib/python3.6/site-packages/astrodendro/plot.py in get_lines(self, structures, subtree, **kwargs) 191 else: 192 if subtree: --> 193 if type(structures[0]) is int: 194 structure = self.dendrogram[structures[0]] 195 else: TypeError: 'int' object is not subscriptable
e-koch commented 4 years ago

This is still an issue for the last release (0.2.0) but was fixed at some point in the current dev version (also noted in #157).

While a new release should be prioritized, the solution for users is to install the dev branch:

pip install git+https://github.com/dendrograms/astrodendro.git
astrojysun commented 2 years ago

I have upgraded to 0.3.0.dev0 but am still getting the same error...

rolando980709 commented 2 years ago

The error is because the function actually expects a list, so a dumb way to fix it is 8-->[8], or modify the source code so that instead of taking the elements from the input (structure[0]) take the entrance directly.

So:

fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)

# Plot the whole tree
p1.plot_tree(ax, color='black')

# Highlight two branches
p1.plot_tree(ax, structure=[8], color='red', lw=2, alpha=0.5)
p1.plot_tree(ax, structure=[24], color='orange', lw=2, alpha=0.5)

# Add axis labels
ax.set_xlabel("Structure")
ax.set_ylabel("Flux")
battersbot commented 1 year ago

Bringing this up again as I came across this bug again. The fix suggested by rolando works for me - suggest that the source code be updated to address this!

And thanks for the fix in the meantime rolando!

keflavich commented 1 year ago

Could you submit a PR with the suggested change @rolando980709? Your snippet suggests a workaround but not the fix.

@battersbot until the change is merged, the workaround is straightforward and is what I'd suggest using. If there's some reason you can't, though, more information would be helpful (e.g., if you encounter this error during GUI operations).

astrojysun commented 1 year ago

Sorry for jumping in here... One thing I would suggest is to edit the code example here to use lists instead of single integers as input. The current example will not work until the suggested change is implemented, and it might confuse new users.

astrofrog commented 1 year ago

I think this might be fixed by https://github.com/dendrograms/astrodendro/pull/168 - we should clean up and merge that PR.