ContextLab / hypertools

A Python toolbox for gaining geometric insights into high-dimensional data
http://hypertools.readthedocs.io/en/latest/
MIT License
1.82k stars 160 forks source link

If legend is not explicitly given, compute from group #131

Closed alysivji closed 7 years ago

alysivji commented 7 years ago

To close https://github.com/ContextLab/hypertools/issues/97

Moved the handle legend block and used the results of the group data block to calculate the legend, as required.

Let me know if this works or if you need me to edit something.

Thanks

andrewheusser commented 7 years ago

thanks @alysivji ! I'll take a look at the code tomorrow - in the meantime, if you could update the docstring to reflect the change, i'd appreciate it!

jeremymanning commented 7 years ago

thanks @alysivji!

i took a quick look at the code and it looks good, although i haven't actually tested it.

question for us to think about: are there any strange group/legend cases to consider here?

alysivji commented 7 years ago

Updated the docstring.

Just one thing I noticed is that sometimes groups change when rerunning code blocks. So Group 1 isn't always Group 1, sometimes it might be labelled Group 2. That might be caused by the set function. Not too sure if set keeps order the same each time.

andrewheusser commented 7 years ago

ah, yes - i've run into that annoying issue before. i think you can fix it by replacing set with:

sorted(set(group), key=list(group).index)

this should make the order consistent

alysivji commented 7 years ago

I changed my code and now when I try to run the following:

import hypertools as hyp
import scipy.io as sio
import numpy as np

data = hyp.tools.load('weights_sample')

group=[]
for idx,i in enumerate(data):
    tmp=[]
    for iidx,ii in enumerate(i):
            tmp.append(int(np.random.randint(1000, size=1)))
    group.append(tmp)

hyp.plot(data, '.', group=group, legend=True)

Legend order changes around each time it is run. How to proceed?

andrewheusser commented 7 years ago

hmm, ill take a look at it and get back in a sec!

andrewheusser commented 7 years ago

ah! the issue is that int(np.random.randint(1000, size=1)) is generating random values, so we would expect the legend to also be random (they are different numbers each time)

I tested the ordering issues after changing set(group) to sorted(set(group), key=list(group).index) and it seems to be the same every time. want to commit a change, and then i'll check this over and merge?

alysivji commented 7 years ago

Ahh yes, that makes sense. I need my coffee =)

Updated the PR. It was fun getting to know this lib yesterday. Definitely will be using it for some analyses.

andrewheusser commented 7 years ago

Awesome, thanks for contributing your time! We appreciate it :)

If you have questions, or comments about how to make the code better, feel free to share as things come up, either on the gitter or issues

andrewheusser commented 7 years ago

lgtm!