from __future__ import print_function
from __future__ import unicode_literals
from __future__ import division
from __future__ import absolute_import
from future import standard_library
standard_library.install_aliases()
import argparse

import matplotlib.pyplot as plt
import pandas as pd


def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('scores', type=str, help='specify path of scores.txt')
    parser.add_argument('--title', type=str, default=None)
    args = parser.parse_args()

    scores = pd.read_csv(args.scores, delimiter='\t')
    for col in ['mean', 'median']:
        plt.plot(scores['steps'], scores[col], label=col)
    if args.title is not None:
        plt.title(args.title)
    plt.xlabel('steps')
    plt.ylabel('score')
    plt.legend(loc='best')
    fig_fname = args.scores + '.png'
    plt.savefig(fig_fname)
    print('Saved a figure as {}'.format(fig_fname))

if __name__ == '__main__':
    main()

from __future__ import print_function
from __future__ import unicode_literals
from __future__ import division
from __future__ import absolute_import
from future import standard_library
standard_library.install_aliases()
import argparse
import os

import matplotlib.pyplot as plt
import pandas as pd


def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--title', type=str, default='')
    parser.add_argument('--file', action='append', dest='files',
                        default=[], type=str,
                        help='specify paths of scores.txt')
    parser.add_argument('--label', action='append', dest='labels',
                        default=[], type=str,
                        help='specify labels for scores.txt files')
    args = parser.parse_args()

    assert len(args.files) > 0
    assert len(args.labels) == len(args.files)

    for fpath, label in zip(args.files, args.labels):
        if os.path.isdir(fpath):
            fpath = os.path.join(fpath, 'scores.txt')
        assert os.path.exists(fpath)
        scores = pd.read_csv(fpath, delimiter='\t')
        plt.plot(scores['steps'], scores['mean'], label=label)

    plt.xlabel('steps')
    plt.ylabel('score')
    plt.legend(loc='best')
    if args.title:
        plt.title(args.title)

    fig_fname = args.files[0] + args.title + '.png'
    plt.savefig(fig_fname)
    print('Saved a figure as {}'.format(fig_fname))

if __name__ == '__main__':
    main()

Support plotting multiple score files
Support plotting multiple score files

  from __future__ import print_function
  from __future__ import unicode_literals
  from __future__ import division
  from __future__ import absolute_import
  from future import standard_library
  standard_library.install_aliases()
  import argparse
+ import os
  
  import matplotlib.pyplot as plt
  import pandas as pd
  
  
  def main():
      parser = argparse.ArgumentParser()
-     parser.add_argument('scores', type=str, help='specify path of scores.txt')
-     parser.add_argument('--title', type=str, default=None)
+     parser.add_argument('--title', type=str, default='')
+     parser.add_argument('--file', action='append', dest='files',
+                         default=[], type=str,
+                         help='specify paths of scores.txt')
+     parser.add_argument('--label', action='append', dest='labels',
+                         default=[], type=str,
+                         help='specify labels for scores.txt files')
      args = parser.parse_args()
  
+     assert len(args.files) > 0
+     assert len(args.labels) == len(args.files)
+ 
+     for fpath, label in zip(args.files, args.labels):
+         if os.path.isdir(fpath):
+             fpath = os.path.join(fpath, 'scores.txt')
+         assert os.path.exists(fpath)
-     scores = pd.read_csv(args.scores, delimiter='\t')
+         scores = pd.read_csv(fpath, delimiter='\t')
-     for col in ['mean', 'median']:
-         plt.plot(scores['steps'], scores[col], label=col)
+         plt.plot(scores['steps'], scores['mean'], label=label)
+ 
-     if args.title is not None:
-         plt.title(args.title)
      plt.xlabel('steps')
      plt.ylabel('score')
      plt.legend(loc='best')
-     fig_fname = args.scores + '.png'
+     if args.title:
+         plt.title(args.title)
+ 
+     fig_fname = args.files[0] + args.title + '.png'
      plt.savefig(fig_fname)
      print('Saved a figure as {}'.format(fig_fname))
  
  if __name__ == '__main__':
      main()
  
Support plotting multiple score files
## Code Before:
from __future__ import print_function
from __future__ import unicode_literals
from __future__ import division
from __future__ import absolute_import
from future import standard_library
standard_library.install_aliases()
import argparse

import matplotlib.pyplot as plt
import pandas as pd


def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('scores', type=str, help='specify path of scores.txt')
    parser.add_argument('--title', type=str, default=None)
    args = parser.parse_args()

    scores = pd.read_csv(args.scores, delimiter='\t')
    for col in ['mean', 'median']:
        plt.plot(scores['steps'], scores[col], label=col)
    if args.title is not None:
        plt.title(args.title)
    plt.xlabel('steps')
    plt.ylabel('score')
    plt.legend(loc='best')
    fig_fname = args.scores + '.png'
    plt.savefig(fig_fname)
    print('Saved a figure as {}'.format(fig_fname))

if __name__ == '__main__':
    main()

## Instruction:
Support plotting multiple score files
## Code After:
from __future__ import print_function
from __future__ import unicode_literals
from __future__ import division
from __future__ import absolute_import
from future import standard_library
standard_library.install_aliases()
import argparse
import os

import matplotlib.pyplot as plt
import pandas as pd


def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--title', type=str, default='')
    parser.add_argument('--file', action='append', dest='files',
                        default=[], type=str,
                        help='specify paths of scores.txt')
    parser.add_argument('--label', action='append', dest='labels',
                        default=[], type=str,
                        help='specify labels for scores.txt files')
    args = parser.parse_args()

    assert len(args.files) > 0
    assert len(args.labels) == len(args.files)

    for fpath, label in zip(args.files, args.labels):
        if os.path.isdir(fpath):
            fpath = os.path.join(fpath, 'scores.txt')
        assert os.path.exists(fpath)
        scores = pd.read_csv(fpath, delimiter='\t')
        plt.plot(scores['steps'], scores['mean'], label=label)

    plt.xlabel('steps')
    plt.ylabel('score')
    plt.legend(loc='best')
    if args.title:
        plt.title(args.title)

    fig_fname = args.files[0] + args.title + '.png'
    plt.savefig(fig_fname)
    print('Saved a figure as {}'.format(fig_fname))

if __name__ == '__main__':
    main()
