栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

从seaborn swarmplot获取绘制点的跨度

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

从seaborn swarmplot获取绘制点的跨度

您可以从中

collections
创建的信息
swarmplot

swarmplot
实际返回matplotlib
Axes
实例,然后从那里可以找到
PathCollections
它创建的实例。要获取职位,我们可以使用
.get_offsets()

这是您的示例,进行了修改以查找并打印群限制,然后使用它们在群周围绘制方框。

import pandas as pdimport numpy as npimport matplotlib.pyplot as pltimport seaborn as sbfrom matplotlib.patches import Rectangle# Generate dummy data.a = np.random.random(75)b = np.random.random(75) - 0.6c = np.random.random(75) + 0.75# Collate into a Dataframedf = pd.Dataframe({'a': a, 'b': b, 'c': c}) df.columns = [list(['WT', 'MUT', 'WTxMUT']), list(['Parent', 'Parent', 'Offspring'])]df.columns.names = ['Genotype', 'Status']df_melt = pd.melt(df)ax = sb.swarmplot(data = df_melt, x = "Status", y = "value", hue = "Genotype")def getdatalim(coll):    x,y = np.array(coll.get_offsets()).T    try:        print 'xmin={}, xmax={}, ymin={}, ymax={}'.format(     x.min(), x.max(), y.min(), y.max())        rect = Rectangle((x.min(),y.min()),x.ptp(),y.ptp(),edgecolor='k',facecolor='None',lw=3)        ax.add_patch(rect)    except ValueError:        passgetdatalim(ax.collections[0]) # "Parent"getdatalim(ax.collections[1]) # "Offspring"plt.show()

打印:

xmin=-0.107313729132, xmax=0.10661092707, ymin=-0.598534246847, ymax=0.980441247759xmin=0.942829146473, xmax=1.06105941656, ymin=0.761277608688, ymax=1.74729717464

这是图:



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/379978.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号