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

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

Open
battersbot opened this issue Feb 5, 2018 · 12 comments
Assignees

Comments

@battersbot
Copy link

battersbot commented Feb 5, 2018

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
Copy link
Contributor

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.

@astrofrog astrofrog self-assigned this Feb 5, 2018
@battersbot
Copy link
Author

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
Copy link
Author

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

Thank you!

@AstroJLo
Copy link

AstroJLo commented Mar 8, 2018

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
Copy link

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
Copy link
Contributor

e-koch commented Sep 25, 2019

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
Copy link

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

@rolando980709
Copy link

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
Copy link
Author

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
Copy link
Contributor

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
Copy link

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
Copy link
Contributor

I think this might be fixed by #168 - we should clean up and merge that PR.

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

8 participants