0
votes

I have 5 different lists y_0,y_1,y_2,y_3 and y_4 : Each of which contain 450120 probability values. The corresponding values of each of the lists add up to 1, i.e, y_0[n] + y_1[n] + y_2[n] + y_3[n] + y_4[n] = 1 for any 'n'.

The X axis contains the indices or the time steps, which are numbers sequentially ranging from 0 to 450119. I want to plot the Y values such that the corresponding probability values or entries of the 5 lists at a given index are plotted on top of one another in different colors. For example: If y_0[0] = 0.2 , y_1[0] = 0.3, y_2[0] = 0.1, y_3[0] = 0.3, y_4[0] = 0.1. So at x=0, I want the following: y_0[0] to be plotted in red from 0 to 0.2 , y_1[0] to be plotted in green from 0.2 to 0.5, y_2[0] to be plotted in yellow from 0.5 to 0.6, y_3[0] to be plotted in blue from 0.6 to 0.9, y_4[0] to be plotted in pink from 0.9 to 1.

And this must repeat for all x values from 0 to 450119.

Currently, I am getting many blank spaces in the plot, as well as many overlaps. Class C5 is not visible at all.enter image description here

def plotAllClassesInOne(y_indices,y_0,y_1,y_2,y_3,y_4,filename):
    plt.xlabel('Time in seconds')
    plt.ylabel('P(Y|X)')
    plt.plot(y_indices, plott(y_0), 'y',label='C1')
    plt.plot(y_indices, plott([sum(x) for x in zip(y_0,y_1)]), 'r',label='C2')
    plt.plot(y_indices, plott([sum(x) for x in zip(y_0,y_1,y_2)]), 'g',label='C3')
    plt.plot(y_indices, plott([sum(x) for x in zip(y_0,y_1,y_2,y_3)]), 'b',label='C4')
    plt.plot(y_indices, plott([sum(x) for x in zip(y_0,y_1,y_2,y_3,y_4)]), 'k',label='C5') 
    plt.legend()
    fig1 = plt.gcf()
    fig1.savefig(filename)
    plt.close()
1
I hope you are aware that there is no monitor with 400000 pixels in width, and hence not all points can be shown anyways?!ImportanceOfBeingErnest

1 Answers

0
votes

Is this what you're trying to do?

def plotAllClassesInOne(y_indices,y_0,y_1,y_2,y_3,y_4,filename):

    length = y_0.shape[0]
    xaxis = np.arange(0, length)
    c1_base = np.zeros(length)
    c1_height = y_0

    c2_base = c1_height
    c2_height = c2_base + y_1

    c3_base = c2_height
    c3_height = c3_base + y_2

    c4_base = c3_height
    c4_height = c4_base + y_3

    c5_base = c4_height
    c5_height = c5_base + y_4

    plt.xlabel('Time in seconds')
    plt.ylabel('P(Y|X)')
    ax.fill_between(xaxis, c1_base, c1_height, label='C1', color='y')
    ax.fill_between(xaxis, c2_base, c2_height, label='C2', color='r')
    ax.fill_between(xaxis, c3_base, c3_height, label='C3', color='g')
    ax.fill_between(xaxis, c4_base, c4_height, label='C4', color='b')
    ax.fill_between(xaxis, c5_base, c5_height, label='C5', color='k')
    plt.legend()
    fig1 = plt.gcf()
    fig1.savefig(filename)
    plt.close()