Skip to content

Commit

Permalink
revised argparse. completed
Browse files Browse the repository at this point in the history
  • Loading branch information
MasaYan24 committed Aug 27, 2018
1 parent 7535bdc commit 41e5a37
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions plot_bin.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ def __init__(self,datafile="score.csv",figfile="score.png",cols=[0],sep='\t',tri
self.__readfile(datafile=datafile,columns=cols)
self.__trim = trim
self.__flag_ave_label = flag_ave_label
print("#################",self.__flag_ave_label)
if labels is not None:
self.__labels = labels

Expand All @@ -37,10 +36,10 @@ def __trim(self,_x):
def plot(self):
if self.__flag_ave_label:
for i in range(len(self.__labels)):
self.__labels[i] = self.__labels[i] + "(" + str(self.__average[i]) + ")"
font = {'family': 'Meiryo'}
self.__labels[i] = self.__labels[i] + "(" + '{:.1f}'.format(self.__average[i]) + ")"
#font = {'family': 'Meiryo'}
#font = {'family': 'Osaka'}
matplotlib.rc('font', **font)
#matplotlib.rc('font', **font)
cmap = plt.get_cmap("tab10")
fig = plt.figure()
ax = fig.add_subplot(1,1,1)
Expand All @@ -51,8 +50,8 @@ def plot(self):
ax.set_xlim([0,100])
#ax.hist(self.__data.values,range=(0,100),rwidth=1.0)
ax.hist(self.__data.values,range=(0,100))
for i in self.__data.columns:
ax.axvline(self.__average[i],color=cmap(i),alpha=0.5)
# for i in self.__data.columns:
# ax.axvline(self.__average[i],color=cmap(i),alpha=0.5)
try:
plt.legend(self.__labels)
except:
Expand All @@ -66,13 +65,13 @@ def plot(self):
class CustomFormatter(argparse.ArgumentDefaultsHelpFormatter,argparse.MetavarTypeHelpFormatter):
pass
parser = argparse.ArgumentParser(description="Plot score.",epilog="example: ./plot_bin.py --columns 0 2 --labels \"テスト\" \"総合\"", formatter_class=CustomFormatter)
parser.add_argument('--file', '--datafile', type=str, dest='datafile', nargs=1, default='score.csv', help="input file")
parser.add_argument('--fig','--figfile', type=str, dest='figfile', nargs=1, default='score.png', help="output figure file (png)")
parser.add_argument('--file', '--datafile', type=str, dest='datafile', nargs='?', default='score.csv', help="input file")
parser.add_argument('--fig','--figfile', type=str, dest='figfile', nargs='?', default='score.png', help="output figure file (png)")
parser.add_argument('--columns','--cols', type=int, dest='columns', nargs='+', default=[0], help="column of data")
parser.add_argument('--labels', type=str, dest='labels', nargs='+', default=None, help="title column")
parser.add_argument('--avelabels', action="store_true", dest='flagavelabel', help="add average value to labels")
parser.add_argument('--notrim', action="store_false", help="do not round-up/down score")
parser.add_argument('--sep', type=str, dest='sep', nargs=1, default='\t', help="specify data separater in datafile")
parser.add_argument('--sep', type=str, dest='sep', nargs='?', default='\t', help="specify data separater in datafile")

args = parser.parse_args()

Expand Down

0 comments on commit 41e5a37

Please sign in to comment.