我想用Python代替JavaScript来绘制UpSet图,并在github上找到py-upset:https://github.com/ImSoErgodic/py-upset/
我将PyCharm用作IDE,并下载了所有要求。

我尝试了下面的代码;

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)


运行代码后,它显示“处理以退出代码0完成”,但未提供任何图形/图表。如何获得图表?有什么帮助吗?

最佳答案

编辑:
刚刚意识到您正在使用命令行。 MatPlotLib默认情况下渲染到窗口,并且不保存到文件。看到
Save plot to image file instead of displaying it using Matplotlib。 (我在下面添加了它。)



我发现了另一个软件包UpSetPlot,该软件包仍在维护中,并具有更易理解的文档。这是一个简短的示例(请注意,我实际上并不认识任何一位作者或他们的披萨偏好):

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")


python - 需要帮助py-upset?-LMLPHP

08-19 21:12