栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

python实现绘制多组并列条形图

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

python实现绘制多组并列条形图

实现功能:

python实现绘制多组并列条形图

输入多个类别的多个特征值,即一个每个种类都有几种特征,在同一个条形图中绘制出这几个种类的所有特征值,用于对比分析。

实现代码:

import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns

def Draw_Parallel_bar(features,L1,L2,L3,L4,L5):
    features=features
    RA=L1;SS=L2;SLE=L3;Arthritis=L4;CTD=L5

    bar_width = 0.1
    index_RA = np.arange(len(features))
    index_SS = index_RA + bar_width
    index_SLE = index_SS + bar_width
    index_Arthritis = index_SLE + bar_width
    index_CTD = index_Arthritis + bar_width

    font = {'family': 'Times New Roman',
            'size': 12,
            }
    sns.set(font_scale=1.2)
    plt.rc('font',family='Times New Roman')

    plt.bar(index_RA, height=RA, width=bar_width, color='peru', label='RA')
    plt.bar(index_SS, height=SS, width=bar_width, color='g', label='SS')
    plt.bar(index_SLE, height=SLE, width=bar_width, color='y', label='SLE')
    plt.bar(index_Arthritis, height=Arthritis, width=bar_width, color='c', label='OA')
    plt.bar(index_CTD, height=CTD, width=bar_width, color='violet', label='CTDs')

    plt.legend(fontsize = 12)  # 显示图例
    plt.xticks(index_RA + 10*bar_width/5, features,fontsize = 12)
    plt.xlabel('Autoantibodies',fontsize = 14)
    plt.ylabel('Positive rate',fontsize = 14)
    plt.show()

if __name__=="__main__":
    Draw_Parallel_bar(('CCP', 'MCV', 'AKA', 'RF', 'ANA','CRP','ESR'),
                      [0.9265,0.8840,0.4816,0.8779,0.6167,0.6012,0.8562],
                      [0.1860,0.3256,0.1163,0.7674,0.7442,0.2558,0.5814],
                      [0.1905,0.3810,0.0476,0.6667,0.8571,0.3333,0.8571],
                      [0.4211,0.7368,0.2105,0.6316,0.5789,0.4737,0.7368],
                      [0.2308,0.3077,0.0769,0.8462,0.8468,0.3846,0.7692])

实现效果:

喜欢记得点赞,在看,收藏,

关注V订阅号:数据杂坛,获取完整代码和效果,将持续更新!

 

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

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

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