UpSetPlot icon indicating copy to clipboard operation
UpSetPlot copied to clipboard

min_subset_size expressed as a percentage / fraction

Open MeHelmy opened this issue 2 years ago • 15 comments

Hi, Thank you for your support.

I tried to filter values with min_subset_size=0.1 when using show_percentages but it did not filter (will work if I set both show_percentages and show_count to True).

Another question (please let me know If I need to move it as separate one)

When using upset.add_stacked_bars and another method, ex: upset.add_catplot How I can control the legend location for each plot?

I used fig.legend(loc=(1, .7)) but it will work for one only, not both.

Thanks, Medhat

MeHelmy avatar Nov 15 '21 20:11 MeHelmy

Hi @MeHelmy, thanks for raising the issue. To help investigate, would you be able to provide complete, runnable code snippets that reproduce the issues?

jnothman avatar Nov 18 '21 10:11 jnothman

Thank you!

Here is an example:

import pandas as pd
import numpy as np
mydf = pd.DataFrame(np.random.randint(2,size=(1000, 4)), columns=list('ABCD'))
mydf['Country'] = pd.DataFrame(np.arange(1000).reshape(1000,1)).applymap(lambda x: np.random.choice(['Ge', 'Eg', 'Ni', 'UN']))

first=True
for i in mydf.columns.tolist()[:-1]:
    if first:
        first=False
        mydf = mydf.set_index(mydf[i] == 1)
    else:
        mydf = mydf.set_index(mydf[i] == 1,  append=True)

from upsetplot import UpSet
from matplotlib import cm
fig = plt.figure(figsize=(20, 10))
upset = UpSet(mydf,
              intersection_plot_elements=0,
              show_percentages=True,
              orientation='vertical',
              show_counts=False,
              min_subset_size=5,
              sort_by='degree',
             )  
upset.add_stacked_bars(by="Country", colors=cm.Pastel1,
                       title="Count by country", 
                        elements=20,
                      )
fig.legend(loc=(1, 1))
upset.plot()

That results in this plot: Screen Shot 2021-11-18 at 10 06 47 AM

So, I used min_subset_size=5 so I think I should not see 4.6% I tried to control the legend position looks like I am doing it wrong, lastly the annotation on the vertical bars are not clear can I change the annotation to be horizontal? (I know we can change the font by using mpl.rcParams['font.size'] = 10 or so, but this is not the case here).

Thanks, Medhat

MeHelmy avatar Nov 18 '21 16:11 MeHelmy

Are you saying that you want min_subset_size to also operate in percentages? Personally I find it very surprising behaviour if I had code

UpSet(mydf, min_subset_size=20)

and then added a parameter related to display

UpSet(mydf, min_subset_size=20, show_percentages=True)

and got an altogether different plot.

jnothman avatar Nov 21 '21 10:11 jnothman

Are you able to share code for your other issue with legends?

jnothman avatar Nov 21 '21 10:11 jnothman

Are you saying that you want min_subset_size to also operate in percentages? Personally I find it very surprising behaviour if I had code

UpSet(mydf, min_subset_size=20)

and then added a parameter related to display

UpSet(mydf, min_subset_size=20, show_percentages=True)

and got an altogether different plot.

I understand your point, let me put it this way, can I filter intersects to include only intersects representing more than 2% (just a random number here)?

MeHelmy avatar Nov 21 '21 15:11 MeHelmy

Are you able to share code for your other issue with legends?

It is in the same mentioned plot.

MeHelmy avatar Nov 21 '21 15:11 MeHelmy

We could support something like min_subset_frac=.2, or min_subset_size="20%", but we do not support these at present

jnothman avatar Nov 21 '21 20:11 jnothman

We could support something like min_subset_frac=.2, or min_subset_size="20%", but we do not support these at present

Sure! I was suggesting an idea :)

Best, Medhat

MeHelmy avatar Nov 21 '21 21:11 MeHelmy

I've renamed the issue in accordance with this.

jnothman avatar Nov 21 '21 22:11 jnothman

Thank you,

Do you have any suggestions for: fig.legend(loc=(1, 1)) and The annotation on the vertical bars, If I can change the annotation to be horizontal?

Thanks! Medhat

MeHelmy avatar Nov 21 '21 22:11 MeHelmy

I will admit legend placement is not within my expertise... Not sure what you're asking about annotations; label your picture?

jnothman avatar Nov 22 '21 21:11 jnothman

Thank you,

The annotation I mean upper left corner (red arrow).

142452132-84dc2f58-a38c-449e-94ab-0c236529c35d

MeHelmy avatar Nov 22 '21 21:11 MeHelmy

You want that text rotated? Currently you would have to get the axes returned by the plot() method, find the annotations and modify them...

jnothman avatar Nov 23 '21 00:11 jnothman

Thank you!

MeHelmy avatar Nov 23 '21 00:11 MeHelmy

I'm reopening this until we have a solution for min_subset_size expressed as a fraction

jnothman avatar Nov 23 '21 10:11 jnothman

I'm actually going to open a new issue so I don't need to keep reading this thread when I get occasion to work on this package .

jnothman avatar Dec 28 '23 14:12 jnothman