"""
とにかくCSVを可視化する
"""
import json
import codecs
import numpy
import datetime
import os
from matplotlib import pyplot as plt
import pandas as pd
MYDIR = os.path.dirname(__file__)
def visualize(df, options={}):
"""
"""
nrow = len(df.columns) - 1
fig = plt.figure(figsize=(16, 9))
axes = fig.subplots(nrow, 1, sharex=True)
x = df[df.columns[0]]
x = list(map(lambda t: datetime.datetime.strptime(t, options["x"]["format"]), x))
j = 0
for i, col in enumerate(df.columns):
ax = axes[j]
if i == 0:
continue
if i == 1:
ax.set_title(options["title"])
y = numpy.array(df[col])
ax.plot(x, y)
ax.set_ylabel(col)
ax.grid(color='lightgray', linestyle='-', linewidth=0.5)
j += 1
plt.subplots_adjust(left=0.05, right=0.95, bottom=0.08, top=0.95, hspace=0.3)
plt.show()
if __name__ == "__main__":
import argparse
parser = argparse.ArgumentParser(description='Process some integers.')
parser.add_argument('filepath', type=str, help='an integer for the accumulator')
parser.add_argument('--xname', default="", type=str, help='an integer for the accumulator')
parser.add_argument('--xtype', default="datetime", type=str, help='an integer for the accumulator')
parser.add_argument('--xformat', default="%Y-%m-%d", type=str, help='an integer for the accumulator')
args = parser.parse_args()
path = args.filepath
options = {
"title": os.path.basename(path),
"x": {
"name": args.xname,
"type": args.xtype,
"format": args.xformat
}
}
df = pd.read_csv(path)
visualize(df, options)