Homework 8

Data Management

Task:

Data management was an introduction into graphing and writing our own classes. The task was to create classes that would be able to create data and plot it as a scatter plot. The first class created was the datum class. This class held functions to set parameters, draw circles as points on a plot, and manipulate them in ways such as moveing them, undrawing them, and changing the color.This was accomplished by using a draw function, set fill, draw parameters, move, and undraw functions. The data was also saved to a file after it was created using read and write functions within the class. After running a test on the comleted datum class, there was a text file written named "testdata.txt." The test itself drew a large circle, then plotted the points according to the data, removed them, changed the color, drew them, and finally changed the color. The second class that was created, tiltled DataCollection was a class that drew a chart, and plotted points on the chart. To accomplish this, datum was one of the classes called in prior to creating the new class. The data points were read and manipulated from the previously created "testdata.txt" file, accomplished by the read function. The data was then appended to a list, which was then referenced in the draw function when plotting the points. The points were plotted on a chart that was created by drawing a rectangle and labeling the axis. The points were the circles created in the datum class under the draw function, which was called in the plot function within the class DataCollection. The test for this class was to draw the chart, plot the points, then move the entire plot, and finally move just the points.

Image from datum.py:

Image from DataCollection.py:

Creating Fields in an Object:

We create fields of a particular object with self.set(). After this field has been set, we can then put data into the fields of a particular object with self.x0=tx for example. An example of creating a field would be: self.set(tx, ty, tz) and then the example of putting a data object into a field would be: self.x=tx self.y=ty self.z=tz then tx, ty, and tz would be assigned values.

Accessing Fields in an Object Inside a Method:

We access fields in an object inside a method by calling them by their method. An example of reading data from a file in order to access the (x,y,z) fields would be: dm.read(fp) self.data.append(dm) These could then be written to a file by means of: for i in self.data: i.write(fp)