#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Felix Muzny DS 2000 9/30/2022 Lecture 7 Example problem --- Write a program, analyze_dist.py, that reads the data from the file muzny_distances.txt and graphs it accordingly on a scatter plot. Use a constant to save the file name. Update the program to plot all points simultaneously. Update the program to plot the strange_distances.txt in a separate series. Add a legend. """ import matplotlib.pyplot as plt # constant # upper case MUZNY_FILE = "muzny_distances.txt" STRANGE_FILE = "strange_distances.txt" # a number that you care about # or a math value w/ a static value PI = 3.14159 # constants are setting up some convenient definitions # whose values won't change over the span of the program # running def main(): file = open(MUZNY_FILE, "r") # list accumulation days = [] miles = [] for line in file: # these are still strings! pieces = line.split() print(pieces) # add information to the correct list days.append(int(pieces[0])) miles.append(float(pieces[1])) # x axis we have day # y axis we have the mileage #plt.plot(int(pieces[0]), float(pieces[1]), "o") # x value and a y-value #plt.bar(int(pieces[0]), float(pieces[1])) # don't forget to close the first file file.close() # syntax for plotting multiple points at the same time # plt.plot(x_coords, y_coords, "o") # plt.bar(x_coords, y_coords) # [29, 28, ....] # [3.01, 4.02, ....] print("days:", days) print("miles:", miles) plt.plot(days, miles, "o", label="Felix") file = open(STRANGE_FILE, "r") # reset the lists to be empty days = [] miles = [] for line in file: # these are still strings! pieces = line.split() print(pieces) # add information to the correct list days.append(int(pieces[0])) miles.append(float(pieces[1])) # don't forget to close the second file file.close() plt.plot(days, miles, "o", label="Laney") # all the plot things that we only want to do once plt.xlabel("Day of the Month") plt.ylabel("Miles") plt.title("Miles run in Sept") plt.legend() plt.show() print() main()