1

I have been trying to get an UpSetPlot to work and have not been having much luck.

My code is quite simple, I have already shaped the data in a CSV. Below is what I have been trying to run.

import pandas as pd
from matplotlib import pyplot as plt
from upsetplot import UpSet
upset = pd.read_csv ("upset.csv")
plot(upset)
pyplot.show()

The data looks like this:

cat0 cat1 cat2 value
FALSE FALSE FALSE 56
FALSE FALSE TRUE 283
FALSE TRUE FALSE 1279
FALSE TRUE TRUE 5882

I based my data off the example used in the UpSetPlot so it should work - Not quite sure where I have gone wrong.

Any feedback would be greatly appreciated!

afroduck
  • 143
  • 8

1 Answers1

1

I think you are missing a step here. After reading the data, you need to convert it to a Upset-compatible format. You can read more about it here.

Based on the steps mentioned, you can to use from_memberships() to convert it before plotting. This will convert the data to a series with multiple indices which is required. Updated code below. I saved your data in excel instead of csv, but should result in same plot.

import pandas as pd
from matplotlib import pyplot as plt
from upsetplot import UpSet, plot, from_memberships
upsetraw = pd.read_excel("input.xlsx", 'Sheet17')
upset = from_memberships(upsetraw)
plot(upset)
plt.show()

Plot

enter image description here

Redox
  • 9,321
  • 5
  • 9
  • 26
  • 1
    Amazing, thanks so much! I did actually come across from_memberships but ended up disregarding as some of the homepage examples don't seem to use it. Works prefect now, cheers! – afroduck Oct 19 '22 at 08:18
  • Hello, the graph is incorrect; the header string "cat0 cat1 cat2" has been divided into characters. Do you know how to correct it? @Redox – Masood Salik Jan 17 '23 at 07:00