Last active
August 23, 2018 08:48
-
-
Save ishidur/76a693e9bdea1cd5308649c3d87360f2 to your computer and use it in GitHub Desktop.
Pandasを使ってグラフを作成 #code
This file contains hidden or 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
import matplotlib.pyplot as plt | |
import numpy as np | |
import pandas as pd | |
import re | |
import glob | |
plt.rcParams['font.family'] = 'sans-serif' # 使用するフォント | |
# x軸の目盛線が内向き('in')か外向き('out')か双方向か('inout') | |
plt.rcParams['xtick.direction'] = 'in' | |
# y軸の目盛線が内向き('in')か外向き('out')か双方向か('inout') | |
plt.rcParams['ytick.direction'] = 'in' | |
plt.rcParams['xtick.major.width'] = 1.0 # x軸主目盛り線の線幅 | |
plt.rcParams['ytick.major.width'] = 1.0 # y軸主目盛り線の線幅 | |
plt.rcParams['font.size'] = 8 # フォントの大きさ | |
plt.rcParams['axes.linewidth'] = 1.0 # 軸の線幅edge linewidth。囲みの太さ | |
def render_result(filename): | |
df = pd.read_csv(filename) | |
# print(df['score']) | |
# df.plot(x=df.columns[0], legend=False, figsize=[10, 8]) | |
ax = df.plot(x=df.columns[0], y=df.columns[1], label='swarm-1', figsize=[10, 8]) | |
df.plot(x=df.columns[0], y=df.columns[2], label='swarm-2', ax=ax) | |
plt.legend(loc='best', fancybox=True, framealpha=1, fontsize=18) | |
plt.ylim(0.0, 1.0) | |
plt.grid(which='major', c='grey', linestyle='-') | |
plt.xlabel('Learning step [-]', fontsize=20) | |
# plt.ylabel('Accuracy rate[%]', fontsize=20) | |
plt.ylabel('Score [-]', fontsize=20) | |
plt.tick_params(labelsize=18) | |
plt.savefig('learning1-score.png', bbox_inches='tight', transparent=False) | |
def render_output(out_filename): | |
df = pd.read_csv(out_filename) | |
df.objsize *= 10 | |
df.plot(x='objsize', figsize=[10, 8], lw=3) | |
plt.grid(which='major', color='grey', linestyle='-') | |
plt.legend(loc='best', fancybox=True, framealpha=1, fontsize=18) | |
plt.tick_params(labelsize=18) | |
plt.xlabel('Object size [mm]', fontsize=20) | |
plt.ylabel('Output [-]', fontsize=20) | |
plt.savefig('learning2-output.png', | |
bbox_inches='tight', transparent=False) | |
plt.savefig('learning2-output.pdf', | |
bbox_inches='tight', transparent=False) | |
def make_label_from_file_output_growth(str): | |
conf = re.findall("[0-9]+", str) | |
return 'learning step:' + conf[0] | |
# return 'input:'+conf[1]+',step:'+conf[0] | |
def sort_rule_output_growth(x): | |
conf = re.findall("[0-9]+", x) | |
return int(conf[0]) | |
def render_output_growth(): | |
n = 1 | |
files = [] | |
files += glob.glob('./data/outputlogs/output_func-*.csv') | |
files = sorted(files, key=sort_rule_output_growth) | |
label = make_label_from_file_output_growth(files[0]) | |
print(label) | |
df = pd.read_csv(files[0]) | |
ax = df.plot(x='objsize', y='goal-'+str(n), lw=3, | |
label=label, figsize=[10, 8]) | |
plt.grid(which='major', color='grey', linestyle='-') | |
for i in range(1, len(files)): | |
data = pd.read_csv(files[i]) | |
label = make_label_from_file_output_growth(files[i]) | |
data.plot(x='objsize', y='goal-'+str(n), lw=3, | |
label=label, ax=ax) | |
ax.tick_params(labelsize=18, direction='in') | |
plt.xlabel('Object size', fontsize=20) | |
plt.ylabel('Output', fontsize=20) | |
plt.legend(loc='best', fancybox=True, fontsize=18) | |
# plt.legend(loc='best', fancybox=True, framealpha=1, fontsize=20) | |
plt.grid(which='major', color='black', linestyle='-') | |
plt.savefig('learning1-output'+str(n)+'-growth.pdf', | |
bbox_inches='tight', transparent=False) | |
plt.savefig('learning1-output'+str(n)+'-growth.png', | |
bbox_inches='tight', transparent=False) | |
if __name__ == "__main__": | |
timestamps=[""] | |
for timestamp in timestamps: | |
result_filename = "data/result" + timestamp + ".csv" | |
render_result(result_filename) | |
out_last_filename = "data/output_last" + timestamp + ".csv" | |
render_output(out_last_filename)' | |
render_output_growth() | |
plt.show() | |
# plt.savefig('plotname.png', bbox_inches='tight', transparent=False) | |
# plt.savefig('plotname.pdf', bbox_inches='tight', transparent=False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment