Skip to content
Snippets Groups Projects
Select Git revision
  • 5265af0b43703e7b8435303c1297f924db57741b
  • master default protected
2 results

lab4-bargraph-multicolor.py

Blame
  • lab4-bargraph-multicolor.py 783 B
    #https://pythonspot.com/matplotlib-bar-chart/
    
    import numpy as np
    import matplotlib.pyplot as plt
    
    # data to plot
    n_groups = 4
    means_frank = (90, 55, 40, 65)
    means_guido = (85, 62, 54, 20)
    
    # create plot
    fig, ax = plt.subplots()
    index = np.arange(n_groups)
    bar_width = 0.35
    opacity = 0.8
    
    rects1 = plt.bar(index, means_frank, bar_width,
                     alpha=opacity,
                     color='b',
                     label='Frank')
    
    rects2 = plt.bar(index + bar_width, means_guido, bar_width,
                     alpha=opacity,
                     color='g',
                     label='Guido')
    
    plt.xlabel('Person')
    plt.ylabel('Scores')
    plt.title('Scores by person')
    plt.xticks(index + bar_width, ('A', 'B', 'C', 'D'))
    plt.legend()
    
    plt.tight_layout()
    plt.show()