UpSetPlot

raw JSON →
0.9.0 verified Fri May 01 auth: no python

A Python library to draw Lex et al.'s UpSet plots using Pandas and Matplotlib. Current version is 0.9.0, with occasional releases.

pip install upsetplot
error AttributeError: module 'upsetplot' has no attribute 'from_indicators'
cause `from_indicators` was removed in version 0.8.0.
fix
Use from upsetplot import from_memberships and convert your indicator matrix to membership lists.
error ValueError: 'degree' is not a valid value for sort_by
cause The `sort_by` parameter no longer accepts 'degree' since version 0.6.0; use 'cardinality'.
fix
Change sort_by='degree' to sort_by='cardinality'.
error ImportError: cannot import name 'UpSet' from 'upsetplot'
cause Older versions of upsetplot (<0.6.0) had the UpSet class in a submodule or different name. Or you have a different library installed.
fix
Ensure you have upsetplot>=0.6.0 installed: pip install -U upsetplot. Use from upsetplot import UpSet.
breaking `from_indicators` was removed in version 0.8.0. Use `from_memberships` or `from_abundance` instead.
fix Replace `from_indicators(membership_matrix)` with `from_memberships(membership_lists)`.
deprecated The `UpSet` class parameter `sort_by` with value 'degree' is deprecated; use 'cardinality'.
fix Change `sort_by='degree'` to `sort_by='cardinality'`.
gotcha When using `UpSet.plot()`, call `plt.show()` explicitly; otherwise the plot may not display in scripts.
fix Add `import matplotlib.pyplot as plt; plt.show()` after `plot.plot()`.
gotcha The `data` parameter in `from_memberships` must be a pandas Series or array of the same length as the membership list.
fix Ensure `data` length matches the number of elements (rows) in the membership lists.

Create a basic UpSet plot from membership lists. Uses `from_memberships` to convert data, then `UpSet().plot()`.

import pandas as pd
from upsetplot import UpSet

data = {
    'ID': [1,2,3,4,5],
    'Set1': [True, True, False, False, True],
    'Set2': [False, True, True, False, False],
    'Set3': [True, False, True, True, False]
}
df = pd.DataFrame(data)
# Convert to indicator format (each row one set?): Actually upsetplot expects memberships
memberships = [
    ['Set1', 'Set3'],
    ['Set1', 'Set2'],
    ['Set2', 'Set3'],
    ['Set3'],
    ['Set1']
]
from upsetplot import from_memberships
upset_data = from_memberships(memberships, data=df['ID'])
plot = UpSet(upset_data, subset_size='count')
plot.plot()
import matplotlib.pyplot as plt
plt.show()