Upset plot using python
1
2
Entering edit mode
2.1 years ago
Ric ▴ 440

Hi, I found the below Upset plot code from Wayne here. The Orthogroups.GeneCount.tsv can be found here

import pandas as pd
dic={'group':[],'sp1':[],'sp2':[],'sp3':[],'sp4':[],'sp5':[],'sp6':[],'total':[]}
with open ("Orthogroups.GeneCount.tsv","r") as f:
    f.readline()
    line = f.readline()
    while line:
        parts = line.strip().split("\t")
        dic['group'].append(parts[0])
        dic['sp1'].append(parts[1])
        dic['sp2'].append(parts[2])
        dic['sp3'].append(parts[3])
        dic['sp4'].append(parts[4])
        dic['sp5'].append(parts[5])
        dic['sp6'].append(parts[6])
        dic['total'].append(parts[7])
        line = f.readline()
df = pd.DataFrame(data=dic).set_index("group")
cols = df.columns[df.dtypes.eq('object')]  # based on https://stackoverflow.com/a/36814203/8508004
df[cols] = df[cols].apply(pd.to_numeric, errors='coerce')  # based on https://stackoverflow.com/a/36814203/8508004
group_dict = {}

for index, row in df.iterrows():
    for sp, count in row.items():
        if sp != "total" and count != 0:
            group_dict.setdefault(index, []).append(sp)
group_dict
# import pyupset as pyu
from upsetplot import UpSet
from upsetplot import from_memberships

x = from_memberships(group_dict.values()).sort_values(ascending=False)
UpSet(x, subset_size='count', show_counts=True).plot()
from matplotlib import pyplot as plt
plt.title("UpSet with catplots, for orientation='horizontal'")
plt.show()

enter image description here

How is it possible to prevent the labels are overlapping?

I appreciate any help you can provide.

Best wishes,

python orthofinder upset • 2.6k views
ADD COMMENT
2
Entering edit mode
2.1 years ago
Shred ★ 1.6k

Just change the element_size= parameter to an higher value.

x = from_memberships(group_dict.values()).sort_values(ascending=False)
UpSet(x, subset_size='count', show_counts=True, element_size=24).plot()
plt.title("UpSet with catplots, for orientation='horizontal'")
plt.show()

Gives

upset_lower

Using instead

x = from_memberships(group_dict.values()).sort_values(ascending=False)
UpSet(x, subset_size='count', show_counts=True, element_size=36).plot()
plt.title("UpSet with catplots, for orientation='horizontal'")
plt.show()

Gives

upset_higher

ADD COMMENT
0
Entering edit mode

It does not work for me. Everything gets smaller except the numbers. enter image description here. What did I miss? P.S. Is it possible to rotate the values to portrait?

ADD REPLY

Login before adding your answer.

Traffic: 1988 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6