zoukankan      html  css  js  c++  java
  • Matplotlib之Bar Chart

    Matplotlib之Bar Chart:

    import numpy as np
    import matplotlib.pyplot as plt
    
    data = [[300, 200, 250, 150, 280],
            [300, 166, 203, 250, 225],
            [100, 110, 115, 150, 112],
            [300, 200, 250, 150, 280],
            [20, 30, 15, 10, 12],
            [20, 10, 10, 10, 20]]
    
    columns = ('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday')
    rows = [x for x in ("EQP.NY", "EQB.NY", "EQP.LN", "EQB.LN", "FIP.NY", "FIB.NY")]
    
    values = np.arange(0, 2000, 500)
    
    # Get some pastel shades for the colors
    colors = plt.cm.YlOrRd(np.linspace(0, 0.7, len(rows)))
    
    n_rows = len(data)
    
    index = np.arange(len(columns)) + 0.3
    bar_width = 0.4
    
    # Initialize the vertical-offset for the stacked bar chart.
    y_offset = np.zeros(len(columns))
    
    # Plot bars and create text labels for the table
    cell_text = []
    for row in range(n_rows):
        plt.bar(index, data[row], bar_width, bottom=y_offset, color=colors[row])
        y_offset = y_offset + data[row]
        cell_text.append(['%u' % x for x in data[row]])
    # Reverse colors and text labels to display the last value at the top.
    colors = colors[::-1]
    cell_text.reverse()
    # print(cell_text)
    
    # Add a table at the bottom of the axes
    the_table = plt.table(cellText=cell_text,
                          rowLabels=rows[::-1],
                          rowColours=colors,
                          colLabels=columns,
                          loc='bottom')
    
    # Adjust layout to make room for the table:
    plt.subplots_adjust(left=0.2, bottom=0.25)
    
    # plt.ylabel("Loss in ${0}'s".format(value_increment))
    plt.ylabel('Break counts')
    # print(values)
    plt.yticks(values, ['%d' % val for val in values])
    plt.xticks([])
    plt.title('Break Recon Summary')
    
    plt.show()
    

    效果:

  • 相关阅读:
    时统设备简介和标准汇总
    html页面元素铺满屏幕
    JavaScript之单线程
    JavaScript 内存模型
    数据-内存-变量
    python+selenium2自动化---通过js脚本给时间控件赋值
    Linux常用命令---文件创建、查找
    python+selenium2自动化---使用pytesseract和Pillow实现验证码识别
    python+selenium2自动化---屏幕截图
    Linux常用命令---find
  • 原文地址:https://www.cnblogs.com/AK47Sonic/p/8645104.html
Copyright © 2011-2022 走看看