Python IndexError: index 16 is out of bounds for axis 0 with size 16 -


i wish use ascii file contains data arranged in several columns , rows (20 columns, 2737 rows). wish plot data 1 column against another. use code:

    import numpy np     import matplotlib.pyplot plt     numpy import *     import math      def plot(matrix):     # counter naming images     = 0      # color scheme     color = np.array([0.4, 0.4, 0.4])     # each row, plot     row in matrix:     counter = 0     x = []     y = []     # uptill end of columns     while counter < 20:     y.append(row[counter])     x.append(row[counter + 1])     counter += 2      t = linspace(1e11, 3e13, 10000)     b = y[2] * (2 * 6.626e-34 * t * t * t / 9e16) * (1 / (exp(6.626e-34 * t / (1.38e-23 * y[1])) - 1)) * (t**x[1])                                                               print (b)     l = 3e14 * 4.042 / t     c = 3e14 / t      plt.plot(l, b, label='shifted spectrum')     plt.plot(c, b, label='restframe spectrum')      # scatter plot     #plt.scatter(y[3], x[2], c=color)     #plt.scatter(y[4], x[3], c=color)     #plt.scatter(y[5], x[4], c=color)     plt.errorbar(y[3], x[2], xerr=0, yerr=x[6], c='r',elinewidth=2.5, markeredgewidth=2)      plt.errorbar(y[4], x[3], xerr=0, yerr=y[7], c='r',elinewidth=2.5, markeredgewidth=2)      plt.errorbar(y[5], x[4], xerr=0, yerr=x[7], c='r',elinewidth=2.5, markeredgewidth=2)       plt.xlim(5, 10000)     plt.ylim(8e-9, 0.1)     # saving image png     plt.yscale('log')     plt.xscale('log')     plt.ylabel('flux (mjy)')     plt.xlabel('observed wavelength (microns)')     plt.text(2000, 0.05, y[0])  # pixelx     plt.text(3500, 0.05, x[0])  # pixely     plt.text(2000, 0.025, x[5])  # sfr     plt.text(2000, 0.01, y[1])  # temp     plt.text(2000, 0.0060, x[1])  # beta     plt.text(2000, 0.0030, y[6])  # minchisq     #plt.text(2000, 0.0015, x[7])  # snrb4     #plt.text(2000, 0.00020, y[7])  # snrb6     #plt.text(2000, 0.00001, x[6])  # snrb7       plt.text(1000, 0.05, 'pixel=')  # pixelx     plt.text(1000, 0.025, 'sfr=')  # pixelx     plt.text(1000, 0.01, 'temp=')  # temp     plt.text(1000, 0.0060, 'beta=')  # beta     plt.text(500, 0.0030, 'minchisq=')  # minchisq     #plt.text(500, 0.0015, 'snrb4=')  # minchisq     #plt.text(500, 0.00020, 'snrb6=')  # minchisq     #plt.text(500, 0.00001, 'snrb7=')  # minchisq      plt.savefig(str(i))     plt.close()      # increment counter naming image     += 1       def generate():     # open file     f = open('sami_new.txt', 'r')      # extract in list format lines in file     temp = [row.split('\t') row in f.readlines()]      # remove ending new line     temp = temp[:len(temp)-1 ]      # cast float     temp = np.array(temp).astype(float)      # plot     plot(temp)      return     generate() 

the code works fine when there lesser columns (less 10) gives error:

traceback (most recent call last):       file "generate_again.py", line 114, in <module>         generate()       file "generate_again.py", line 109, in generate         plot(temp)       file "generate_again.py", line 30, in plot         y.append(row[counter])     indexerror: index 16 out of bounds axis 0 size 16 

i have gone through answers error cannot relate code , cannot understand changes need make. using python3.5 , python2.7. can help? thanks!


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -