On Wed, Jun 29, 2016 at 2:41 PM, Peter Otten <__pete...@web.de> wrote:
> Colin Ross wrote: > > > Good afternoon, > > > > I have a .dat file that is 214 rows by 65 columns that I would like to > > read into python and plot the 1st column versus all other columns. > > > > My code: > > > > ######################################################################### > > > > import numpy as np > > import scipy > > import pylab as pl > > import matplotlib > > from matplotlib.ticker import ScalarFormatter, FormatStrFormatter > > import sys > > > > # Load in text from .dat file > > > > sed = np.loadtxt('spectra.dat', unpack = True) > > for flux in sed: > pl.plot(wavelength, flux) > > > pl.xscale('log') > > > > pl.show() > > > > ######################################################################### > > > > This is fine if I want to write out a separate line for each of the 65 > > columns, but I would like to simplify the code by looping over the data. > > Can someone please help me formatting the loop correctly? > Thank you for the fast response! I have tried this and it outputs the attached image. It seems to only plot 1 curve, when I would have expected 64? > > To understand why the above works (assuming it does) consider that for many > data types > > for item in data: > ... # use item > > is equivalent to > > for index in range(len(data)): > item = data[index] > ... # use item > > Unrolling the above for len(data) == 3 gives: > > item = data[0] > ... # use first item > item = data[1] > ... # use second item > item = data[2] > ... # use third item > > > _______________________________________________ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor > _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor