import os.path import csv from matplotlib import pyplot as plt def graph_one(requested): plt.subplots(figsize=(12, 7)) y = column[requested][2:] y = [float(i) for i in y] x = column[0][2:] plt.title("Measurements for sample {}".format(requested)) plt.xlabel("Attribute") plt.ylabel("Length") plt.ylim(0, 8) plt.bar(x, y, width=1, align="center", color="black") plt.show() def change(wanted_row): if wanted_row == "sepal_length": row_cell = 2 elif wanted_row == "sepal_width": row_cell = 3 elif wanted_row == "petal_length": row_cell = 4 elif wanted_row == "petal_width": row_cell = 5 return row_cell def graph_two(): plt.subplots(figsize=(7.5, 7)) row_list = [] avg_list = [] row_cell = change(wanted_row) for all_columns in range(1, 151): row = column[all_columns][row_cell] row_list.append(float(row)) total = [float(c) for c in column[all_columns][2:row_cell]]+[float(c) for c in column[all_columns][row_cell+1:]] avg = sum(total)/3 avg_list.append(avg) other_attribute_lengths = avg_list attribute_lengths = row_list plt.title("Attribute comparison for {}".format(wanted_row)) plt.xlabel("Attribute measurement") plt.ylabel("Average of other attributes") plt.xlim(0, 6.5) plt.ylim(0, 6.5) plt.plot([0, 6.5], [0, 6.5], color="purple") plt.scatter(attribute_lengths, other_attribute_lengths) plt.show() choice = 0 while choice != 3: if os.path.isfile("iris.csv"): print ("Flower attribute analysis", end="\n") else: print ("File not exist") print() print("Please choose one of: ", " 1 - display flower's measurements", " 2 - display scatter plot of attribute's measurements", " 3 - exit the system", sep="\n") choice = int(input("Your choice? ")) with open("iris.csv", "r", newline='') as input_file: data_list = csv.reader(input_file) column = [ column for column in data_list] if choice == 1: requested = int(input("Please enter flower ID number? ")) if requested < 150 and requested > 0: graph_one(requested) elif choice == 2: rows = {"sepal_length", "sepal_width", "petal_length", "petal_width"} print("Attribute options are: ","\n" "sepal_length", "sepal_width", "petal_length", "petal_width") wanted_row = input("Please enter attribute? ") if rows.__contains__(wanted_row): graph_two() elif choice == 3: print("End") break