Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hi, I am working on a project in Python. It is supposed to read temperatures in

ID: 3917954 • Letter: H

Question

Hi, I am working on a project in Python. It is supposed to read temperatures in a csv file and convert the temperatures from Celsius to Fahrenheit and make a graph. Whenever I run my program, the graphing area is blank and does not use the x or y tickmarks that I specify. This is what I have so far:

import csv
import numpy as np
import matplotlib.pyplot as plt

def main():

temp_file = open('data.csv', "r")
for line in temp_file:
Oslo =[]
  
Harrisburg =[]
  
Honolulu =[]
  
Santiago =[]
  
new_array=[]
  
for year in range(2000,2018):
  
for month in range(1,12):
  
Oslo.append(0)
  
Harrisburg.append(0)
  
Honolulu.append(0)
  
Santiago.append(0)
  
new_array.append(year)
  
plt.plot(new_array, Oslo, 'b-', label = "Oslo")
  
plt.plot(new_array, Harrisburg, 'r-', label = "Harrisburg")
  
plt.plot(new_array, Honolulu, 'g-', label = "Honolulu")
  
plt.plot(new_array, Santiago, 'y-', label = "Santiago")

plt.legend(shadow = True, loc = "best")
  
plt.xticks(np.arange([0, 216, 1.0)]))
plt.yticks(np.arange([-10, 30, 10.0]))
  
plt.xlabel('Year')
plt.ylabel('Temperature')
plt.title("Average Monthly Temperature in Four Cities")

plt.show()
  
  
main()

Any insight would be greatly appreciated. Thank you.

Explanation / Answer

Hi,
So, the first thing that i want to tell you is that, even though i couldn't make out a lot of stuff because i can't see the indented code, but you seem to have put all 0s in the data you're plotting.
You're supposed to put in the csv data after converting into Fahrenheit.
Convert each line from the csv file into fahrenheit using the relation C/5 = (F-32)/9, and then store them in the respective arrays. That will solve your problem.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote