Last active
October 25, 2016 13:26
-
-
Save gocreating/be14a546821e1af58233b6f8bc759617 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding=UTF-8 | |
# Usage: | |
# python plot.py [end_record] | |
# python plot.py [start_record] [end_record] | |
import sys | |
import matplotlib as mpl | |
import matplotlib.pyplot as plt | |
import numpy as np | |
mpl.rcParams['agg.path.chunksize'] = 10000 | |
FILES = [] | |
LABEL = { | |
'ForceX': 'ForceX', | |
'ForceY': 'ForceY', | |
'ForceZ': 'ForceZ', | |
'VibrationX': 'VibrationX', | |
'VibrationY': 'VibrationY', | |
'VibrationZ': 'VibrationZ', | |
'AE_RMS': 'AE_RMS', | |
} | |
FEATURES = [ | |
# { | |
# 'label': LABEL['ForceX'], | |
# 'color': 'r', | |
# 's': 0.5, | |
# 'alpha': 0.3, | |
# }, | |
# { | |
# 'label': LABEL['ForceY'], | |
# 'color': 'g', | |
# 's': 0.5, | |
# 'alpha': 0.3, | |
# }, | |
# { | |
# 'label': LABEL['ForceZ'], | |
# 'color': 'b', | |
# 's': 0.5, | |
# 'alpha': 0.3, | |
# }, | |
# { | |
# 'label': LABEL['VibrationX'], | |
# 'color': 'r', | |
# 's': 0.5, | |
# 'alpha': 0.8, | |
# }, | |
# { | |
# 'label': LABEL['VibrationY'], | |
# 'color': 'g', | |
# 's': 0.5, | |
# 'alpha': 0.8, | |
# }, | |
# { | |
# 'label': LABEL['VibrationZ'], | |
# 'color': 'b', | |
# 's': 0.5, | |
# 'alpha': 0.8, | |
# }, | |
{ | |
'label': LABEL['AE_RMS'], | |
'color': 'y', | |
's': 0.5, | |
'alpha': 0.8, | |
}, | |
] | |
yLabel = ','.join(map(lambda f: f['label'], FEATURES)) | |
CUTTERS = [1, 4, 6] | |
for cutter in CUTTERS: | |
for cut in range(1, 316): | |
cutNumber = '{0:0>3}'.format(cut) | |
FILES.append('../data/training/c{cutter}/c_{cutter}_{cutNumber}.csv'.format(cutter=cutter, cutNumber=cutNumber)) | |
skipRows = 0 | |
maxRows = 250000 | |
sums = {} | |
if len(sys.argv) > 1: | |
maxRows = int(sys.argv[1]) | |
if len(sys.argv) > 2: | |
skipRows = int(sys.argv[1]) | |
maxRows = int(sys.argv[2]) | |
for filename in FILES: | |
# ref: <http://docs.scipy.org/doc/numpy/reference/generated/numpy.genfromtxt.html> | |
data = np.genfromtxt( | |
filename, | |
delimiter=',', | |
skip_header=skipRows, | |
skip_footer=0, | |
names=[ | |
LABEL['ForceX'], | |
LABEL['ForceY'], | |
LABEL['ForceZ'], | |
LABEL['VibrationX'], | |
LABEL['VibrationY'], | |
LABEL['VibrationZ'], | |
LABEL['AE_RMS'], | |
], | |
max_rows=maxRows | |
) | |
rows = len(data[LABEL['ForceX']]) | |
# plt.plot(x,y) | |
x = range(1 + skipRows, 1 + skipRows + rows) | |
for f in FEATURES: | |
y = data[f['label']] | |
plt.scatter(x, y, color=f['color'], s=f['s'], alpha=f['alpha']) | |
# | |
# y = data[LABEL['ForceY']] | |
# plt.scatter(x, y, color='g', s=0.5, alpha=0.8) | |
# | |
# y = data[LABEL['ForceZ']] | |
# plt.scatter(x, y, color='b', s=0.5, alpha=0.8) | |
# y = data[LABEL['VibrationX']] | |
# plt.scatter(x, y, color='r', s=0.5, alpha=0.8) | |
# y = data[LABEL['VibrationY']] | |
# plt.scatter(x, y, color='g', s=0.5, alpha=0.8) | |
# | |
# y = data[LABEL['VibrationZ']] | |
# plt.scatter(x, y, color='b', s=0.5, alpha=0.8) | |
# 設定圖的範圍, 不設的話,系統會自行決定 | |
# rows = len(x) | |
plt.xlim(1 + skipRows, 1 + skipRows + rows) | |
# plt.ylim(-4, 4) | |
# | |
plt.xlabel('time(0.02s)') | |
plt.ylabel(yLabel) | |
cutterString = '{' + ','.join(map(lambda cutter: 'c' + str(cutter), CUTTERS)) + '}' | |
featureString = '{' + yLabel + '}' | |
rowString = '#{start}-#{end}'.format(start=skipRows + 1, end=rows) | |
displayTitle = '{0}.{1} ({2})'.format(cutterString, featureString, rowString) | |
fileName = '{0}.{1}_{2}'.format(cutterString, featureString, rowString) | |
plt.title(displayTitle) | |
plt.savefig('../plots/{0}.jpg'.format(fileName), dpi=300, format='jpg') | |
# plt.show() | |
# plt.clf() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment