반응형
/*********************************************************************************************************
-- Title : [Py2.7] Create Chart from CSV file(odd loading csv file).
-- Reference : pythonprogramming.net
-- Key word : matplotlib pyplot csv numpy loadtxt reader
*********************************************************************************************************/
-- Figure
-- Script
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | # -*- coding: utf-8 -*- import matplotlib.pyplot as plt import csv # ******************************************** # -- Create Chart-1 from CSV file. # ******************************************** x = [] y = [] with open('c:\\samples\\pythonprogramming\\example.txt','r') as csvfile: plots = csv.reader(csvfile, delimiter=',') for row in plots: x.append(int(row[0])) y.append(int(row[1])) plt.plot(x,y, label='Loaded from file!') plt.xlabel('xlabel') plt.ylabel('ylabel') plt.title('Title: Chart from CSV file.') plt.legend() plt.show() # ******************************************** # -- Create Chart-2 from CSV file. # ******************************************** import numpy as np x, y = np.loadtxt('c:\\samples\\pythonprogramming\\example.txt', delimiter=',', unpack=True) plt.plot(x,y, label='Loaded from file!') plt.xlabel('xlabel') plt.ylabel('ylabel') plt.title('Title: Chart from CSV file.') plt.legend() plt.show() | cs |
-- Files
반응형