Question: I have written the code for this problem, which is just graphing x and y values of an input file. However I am getting error

I have written the code for this problem, which is just graphing x and y values of an input file. However I am getting error messages from the terminal. The error message says:

Traceback (most recent call last):

File "plot.py", line 17, in

fourth = (parts[1])

IndexError: list index out of range"

Code:

import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as plt import argparse

parser = argparse.ArgumentParser () parser.add_argument('--input', required = True, help="The name of the data file containing sample polynomial data") arguments = parser.parse_args()

x_values = [] y_values = []

with open(arguments.input) as input_file: for line in input_file: parts = line.split(',') third = (parts[0]) fourth = (parts[1]) x_values.append(third) y_values.append(fourth)

print x_values print len(x_values[0:-1]) lists = [-10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10] months = lists print months

plt.xlabel('Time (sec)') plt.ylabel('Signal Strength') plt.title('Signal Strength vs. Time for Relative Activation Energies') plt.plot(x, y, line_width=.5) plt.xticks(months) plt.plot(x_values,y_values, 'ro') plt.savefig("Data.png")

Assignment 1:

1. Use argparse to read an input filename from the command line (e.g. myawesomeprogram.py inputfile). If I leave off the command line argument I should get a helpful error message.

2. Read in that file. Use sample_polynomial_data.training.xy which is in the Simple_Fitting_Data directory.

3. Use pyplot (within matplotlib) to plot the data complete with a descriptive title, axis titles, etc. Take time to play around with different ways to represent the data (lines, dots, triangles, different colors). For the axes, assume that the x axis is time in seconds and the y axis is some generic signal strength.

(Be sure that your python program and plot have names that make sense. For instance, your name and something about assignment 1 would seem like good choices.)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!