mercredi 29 juin 2016

How to plot multiple bars in the same graph

I want to plot 6 different bars (AWA, Rem, S1, S2, SWS, stades) for each group. There are 4 groups.

I know the problem is in the: fig, ax=plt.subplots() How can I fix this?

    import numpy as np
    import matplotlib.pyplot as plt
    %matplotlib inline

    N = 4 # groups: EEG_EMG_EOG_twins(28), EEG_EMG_EOG(26), EEG_twins(22), EEG(20)

    AWA = (99, 98, 98, 95)  #EEG_EMG_EOG_twins(28), EEG_EMG_EOG(26), EEG_twins(22), EEG(20)

    ind = np.arange(N)  # the x locations for the groups
    width = 0.35       # the width of the bars

    fig, ax = plt.subplots()
    rects1 = ax.bar(ind, AWA, width, color='r')

    Rem = (100, 99, 97, 94)  #EEG_EMG_EOG_twins(28), EEG_EMG_EOG(26), EEG_twins(22), EEG(20)
    rects2 = ax.bar(ind + width, Rem, width, color='y')

    S1 = (98, 97, 95, 93)  #EEG_EMG_EOG_twins(28), EEG_EMG_EOG(26), EEG_twins(22), EEG(20)
    rects3 = ax.bar(ind + width, S1, width, color='b')

    S2 = (99, 99, 95, 92)  #EEG+EMG+EOG+twins(28), EEG+EMG+EOG(26), EEG+twins(22), EEG(20)
    rects4 = ax.bar(ind + width, S2, width, color='g')

    SWS = (99, 100, 95, 94)  #EEG+EMG+EOG+twins(28), EEG+EMG+EOG(26), EEG+twins(22), EEG(20)
    rects5 = ax.bar(ind + width, SWS, width, color='y')

    stades = (99, 98, 92, 86)  #EEG+EMG+EOG+twins(28), EEG+EMG+EOG(26), EEG+twins(22), EEG(20)
    rects6 = ax.bar(ind + width, stades, width, color='b')

    # add some text for labels, title and axes ticks
    ax.set_ylabel('Accuracy')
    ax.set_title('Accuracy by group - RF')
    ax.set_xticks(ind + width)
    ax.set_xticklabels(('G1', 'G2', 'G3', 'G4'))

    ax.legend((rects1[0], rects2[0], rects3[0], rects4[0], rects5[0], rects6[0]), ('AWA', 'Rem', 'S1', 'S2', 'SWS', 'stades'))

    plt.show()

enter image description here

Aucun commentaire:

Enregistrer un commentaire