Suppose you want to plot such a csv file with python (matplotlib). ..
$ head tmp2 1000,0.059820690 2000,0.093225007 3000,0.139737644 4000,0.185947643 5000,0.249426903 6000,0.280377022 7000,0.325663341 8000,0.374918515 9000,0.421537361 10000,0.467402504
■ In the case of scatter (scatter plot), plot one by one with a for statement. ■ In the case of plot (line), pass it at once in the list.
It is an image.
Take a look at the code. .. ..
In the case of a polygonal line (note lines 14-16)
1import numpy as np 2import matplotlib.pyplot as plt 3 4data_set = np.loadtxt( 5 fname="tmp2", 6 dtype="float", 7 delimiter=",", 8) 9 10x = [] 11y = [] 12 13for data in data_set: 14 #plt.scatter(data[0], data[1], c='black') 15 x.append(data[0]) 16 y.append(data[1]) 17 18plt.plot(x, y) 19 24plt.show()
For scatter plots (note lines 14-16)
1import numpy as np 2import matplotlib.pyplot as plt 3 4data_set = np.loadtxt( 5 fname="tmp2", 6 dtype="float", 7 delimiter=",", 8) 9 10x = [] 11y = [] 12 13for data in data_set: 14 plt.scatter(data[0], data[1], c='black') 15 #x.append(data[0]) 16 #y.append(data[1]) 17 18plt.plot(x, y) 19 24plt.show()
https://github.com/RuoAndo/qiita/blob/master/plot-x-y.py
Recommended Posts