Question
Hi! I have a question about Python. For my project, I have to read temperatures from a csv file and create a graph with those
Hi! I have a question about Python. For my project, I have to read temperatures from a csv file and create a graph with those values. My graph needs to use the years 2000-2017 as x-axis labels, but also have tickmarks for the months. I also need to convert all the temperatures from Celsius to Fahrenheit. I assume I need to use a nested for loop to extract the data (one loop for the year and one for the month), but I am unsure how to write the loop, especially to keep the previous value when the loop runs again. Here is what I have so far:
import numpy as np import matplotlib.pyplot as plt
def main(): temps = open(data.csv, "r") for year == "2000": for month == "1": Oslo = Harrisburg = Honolulu = Santaiago = years = np.linspace(2000, 2017, 17)
plt.plot(years, Oslo, 'b-', label = "Oslo") plt.plot(years, Harrisburg, 'r-', label = "Harriburg") plt.plot(years, Honolulu, 'g-', label = "Honolulu") plt.plot(years, Santiago, 'y-', label = "Santiago") plt.legend(shadow = True, loc = "best")
plt.xticks(np.arange(0, 12, 1.0)) plt.yticks(np.arange(0, max(temperature), 10.0))
plt.xlabel('Year') plt.ylabel('Temperature')
plt.title("Average Monthly Temperature in Four Cities")
plt.show() main()
Thank you!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started