subplot matplotlib wrong syntax

Posted by madptr on Stack Overflow See other posts from Stack Overflow or by madptr
Published on 2012-11-21T07:24:02Z Indexed on 2012/11/21 11:02 UTC
Read the original article Hit count: 182

I am using matplotlib to subplot in a loop. For instance, i would like to subplot 49 data sets, and from the doc, i implemented it this way;

import numpy as np
import matplotlib.pyplot as plt

X1=list(range(0,10000,1))
X1 = [ x/float(10) for x in X1 ]
nb_mix = 2

parameters = []

for i in range(49):

    param = []

    Y = [0] * len(X1)

    for j in range(nb_mix):

        mean = 5* (1 + (np.random.rand() * 2 - 1 ) * 0.5 )
        var = 10* (1 + np.random.rand() * 2 - 1 )
        scale = 5* ( 1 + (np.random.rand() * 2 - 1) * 0.5 )

        Y = [ Y[k] + scale * np.exp(-((X1[k] - mean)/float(var))**2) for k in range(len(X1)) ] 
        param = param + [[mean, var, scale]]



    ax = plt.subplot(7, 7, i + 1)
    ax.plot(X1, Y)

    parameters = parameters + [param]

ax.show()

However, i have an index out of range error from i=0 onwards.

Where can i do better to have it works ?

Thanks

© Stack Overflow or respective owner

Related posts about python

Related posts about matplotlib