Somehow I used the average temperature data of Saitama and Iwate prefectures. Download here
Load a csv file using NumPy
The function to use when loading is loadtxt
Since a numpy array is returned, prepare a variable to hold it (data_set this time)
import numpy as np
data_set = np.loadtxt(
fname="sampleData.csv", #Path and name of the file to read
dtype="float", #Read with float
delimiter=",", #Since it is csv, separate it with a comma
)
This time with matplotlib, the data read earlier is displayed as a scatter plot.
import matplotlib.pyplot as plt
#Draw a scatter plot
#Please note that the figure is not displayed just by drawing.
for data in data_set:
plt.scatter(data[0], data[1])
plt.title("correlation") #title
plt.xlabel("Average Temperature of SAITAMA") #x-axis label
plt.ylabel("Average Temperature of IWATE") #y-axis label
plt.grid() #Draw a grid line(You don't have to draw)
plt.show() #The figure is displayed by using the show function. It is not displayed unless it is written.
import numpy as np
import matplotlib.pyplot as plt
data_set = np.loadtxt(
fname="sampleData.csv",
dtype="float",
delimiter=",",
)
#Draw a scatter plot → use scatter
#Take out line by line and draw
#plt.scatter(x coordinate value,y coordinate value)
for data in data_set:
plt.scatter(data[0], data[1])
plt.title("correlation")
plt.xlabel("Average Temperature of SAITAMA")
plt.ylabel("Average Temperature of IWATE")
plt.grid()
plt.show()
Next, I will draw a regression line on this scatter plot
・ Reading csv https://www.sejuku.net/blog/73071 ・ Drawing a scatter plot https://pythondatascience.plavox.info/matplotlib/%E6%95%A3%E5%B8%83%E5%9B%B3
Recommended Posts