• python可视化---向饼图中添加表格


    import matplotlib.pyplot as plt
    import matplotlib as mpl
    
    mpl.rcParams["font.sans-serif"] = ["SimHei"]
    mpl.rcParams["axes.unicode_minus"] = False
    
    labels = "A难度水平", "B难度水平", "C难度水平", "D难度水平"
    
    students = [0.35, 0.15, 0.20, 0.30]
    
    colors = ["#377eb8", "#4daf4a", "#984ea3", "#ff7f00"]
              
    explode = (0.1, 0.1, 0.1, 0.1)
    
    plt.pie(students, explode=explode, labels=labels, autopct="%3.1f%%",
            startangle=45, shadow=True, colors=colors)
    
    plt.title("选择不同难度测试试卷的学生百分比")
    
    # 像饼图中添加表格
    colLabels = ["A难度水平", "B难度水平", "C难度水平", "D难度水平"]
    rowLabels = ["学生选择试卷人数"]
    studentValues = [[350, 150, 200, 300]]
    colColors = ["#377eb8", "#4daf4a", "#984ea3", "#ff7f00"]
    
    plt.table(cellText=studentValues,
              cellLoc="center",
              colWidths=[0.1]*4,
              colLabels=colLabels,
              colColours=colColors,
              rowLabels=rowLabels,
              rowLoc="center",
              loc="bottom")
    
    plt.show()

  • 相关阅读:
    世纪末的星期
    马虎的算式
    蜜蜂飞舞
    Torry 的困惑
    级数调和
    数列
    最大最小公倍数
    蚂蚁感冒
    12.integer to Roman
    13.Roman to Integer
  • 原文地址:https://www.cnblogs.com/czz0508/p/10464540.html
Copyright © 2020-2023  润新知