2

I wanted to use Python instead of JavaScript for drawing UpSet diagram and find the py-upset on github: https://github.com/ImSoErgodic/py-upset/ I'm using PyCharm as an IDE and downloaded every requirements.

I tried the code below;

import pyupset as pyu
from pickle import load
with open('./test_data_dict.pckl', 'rb') as f:
    data_dict = load(f)
    pyu.plot(data_dict)

after run the code it says "Process finished with exit code 0" but gives no graph/ diagram. How can I get the diagram? any help?

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
dmsusuz
  • 29
  • 2

3 Answers3

2

EDIT: Just realized you are using the command line. MatPlotLib by default renders to a window and doesn't save to a file. See Save plot to image file instead of displaying it using Matplotlib. (I added it below.)


I found another package, UpSetPlot that's still being maintained and has more understandable documentation. Here's a short example (note i don't actually know any of the authors or their pizza preference):

import matplotlib.pyplot
import pandas
import upsetplot

pizzas = pandas.DataFrame([
    dict(who="Lex", mushroom=True, pineapple=True),
    dict(who="Gehlenborg", mushroom=True),
    dict(who="Strobelt", pineapple=True),
    dict(who="Vuillemot", ),  # cheese!
    dict(who="Pfister", mushroom=True, pineapple=True), 
    dict(who="Nothman", mushroom=True), 
    dict(who="me", mushroom=True, pineapple=True), 
])

toppings = [c for c in pizzas.columns if c != "who"]
toppings_count_series = pizzas.fillna(False).groupby(toppings).count()["who"]

upsetplot.plot(toppings_count_series, sort_by="cardinality")
current_figure = matplotlib.pyplot.gcf()
current_figure.savefig("pizza_toppings.png")

screenshot of upsetplot plot showing a bar chart and connections between sub categories

slushy
  • 3,277
  • 1
  • 18
  • 24
0

Type '% matplotlib inline' at the top of your script. See for reference: Purpose of "%matplotlib inline"

Marla
  • 340
  • 3
  • 16
0

So this may not solve your issue but I had a similar problem (for reasons I haven't researched, but it appears to be a common problem).

The plot is created but just not shown. So to solve this you need to tell matplotlib.pyplot to show the chart.

Do this by including the import statement the plt function (from the matplotlib.pyplot library) -

import matplotlib.pyplot as plt

now at the end of your code and this line -

plt.show(pyu)

Hope this helps!