
今天是我的可视化课程上线的第249天,目前学员425人,每篇原创公众号都会记录这个人数,用来督促和激励我的原创内容。目前课程的主要方向是 科研、统计、地理相关的学术性图形绘制方法,后续也会增加商务插图、机器学等、数据分析等方面的课程。课程免费新增,这点绝对良心!
今天是我的可视化学习社群上线的第28天,目前学员128人,可视化学习社区以我的书籍《科研论文配图绘制指南-基于Python》为基础进行拓展,提供课堂式教学视频,还有更多拓展内容,可视化技巧远超书籍本身,书籍修正和新增都会分享到圈子里面~~
参与课程或者圈子的你将获取到:学员答疑、可视化资源分享、可视化技巧补充、可视化业务代做(学员和甲方对接)、副业交流、提升认知等等。
很多我们课程的学员或者书籍打卡圈子里的同学,都在问我有没有Upset图(UpSet Plot)的绘制方法?。确实,无论是书籍还是对应的可视化课程,Upset图都被我忘记了···,感觉补上。
首先,我们需要知道什么是Upset图?UPSet图形是一种可视化工具,用于展示多个集合之间的共享和差异。它可以帮助我们理解集合之间的交集、并集和差集关系。
UPSet图形通常由两部分组成:矩阵和线性图。
理解和解读UPSet图需要注意以下几个方面:

upset样图
UPSet图形可以提供以下信息:
UPSet图形在生物信息学、数据分析和数据挖掘等领域得到广泛应用。它可以帮助我们发现和分析多个数据集之间的交集和差异,从而揭示数据中的模式和关联关系。
那么,我们该如何绘制UPSet图形呢?
在Python中,可以使用UpSetPlot库来创建UPSet图形。该库提供了灵活的函数和方法,可以根据需求自定义UPSet图形的样式和布局。
pip install upsetplot
UpSetPlot库官网提供了多个绘制案例,小编这里就简单的给大家列举一下:

Plot the distribution of missing values
from matplotlib import pyplot as plt
from upsetplot import generate_counts, plot
example = generate_counts()
plot(example, show_counts=True)
plt.suptitle('Nothing hidden')
plt.show()

Hiding subsets based on size or degree
from matplotlib import pyplot as plt
from upsetplot import generate_counts, plot
example = generate_counts()
plot(example, facecolor="darkblue")
plt.suptitle('facecolor="darkblue"')
plt.show()

Changing Plot Colors
with plt.style.context('dark_background'):
plot(example, show_counts=True, facecolor="red", other_dots_color=.4,
shading_color=.2)
plt.suptitle('dark_background, red face, stronger other colors')
plt.show()

upset = UpSet(example, facecolor="gray")
upset.style_subsets(present="cat0", label="Contains cat0", facecolor="blue")
upset.style_subsets(present="cat1", label="Contains cat1", hatch="xx")
upset.style_subsets(present="cat2", label="Contains cat2", edgecolor="red")
# reduce legend size:
params = {'legend.fontsize': 8}
with plt.rc_context(params):
upset.plot()
plt.suptitle("Styles for every category!")
plt.show()

Highlighting selected subsets