Permalink
Browse files

Add an option to plot just a subsample of the data points.

  • Loading branch information...
1 parent 23fb11d commit ce93b85edefd0674db836ffa824a7aa18729ba74 Leif Johnson committed May 4, 2012
Showing with 13 additions and 6 deletions.
  1. +13 −6 scripts/py-grep-plot
View
@@ -35,17 +35,18 @@ import sys
from matplotlib import pyplot
FLAGS = optparse.OptionParser('Usage: py-grep-plot [OPTIONS] [FILE...]')
-
-FLAGS.add_option('-r', '--regex', default=r'([-+eE.\d]+)', metavar='RE',
- help='extract data points from FILEs with RE ([-+eE.\d]+)')
-FLAGS.add_option('-k', '--column', action='append', type=int, metavar='K',
- help='extract data from the Kth space-separated column')
FLAGS.add_option('-o', '--output', metavar='FILE',
help='save to FILE instead of displaying on screen')
g = optparse.OptionGroup(FLAGS, 'Data Options')
g.add_option('-b', '--batch', type=int, metavar='N',
help='batch data into groups of N points and plot mean + std')
+g.add_option('-e', '--every', type=int, metavar='N',
+ help='restrict plot to show only every Nth data point')
+g.add_option('-k', '--column', action='append', type=int, metavar='K',
+ help='extract data from the Kth space-separated column')
+g.add_option('-r', '--regex', default=r'([-+eE.\d]+)', metavar='RE',
+ help='extract data points from FILEs with RE ([-+eE.\d]+)')
g.add_option('-s', '--smooth', type=int, default=0, metavar='N',
help='smooth across N points before plotting (0)')
FLAGS.add_option_group(g)
@@ -59,7 +60,7 @@ g.add_option('-p', '--points', default='o-', metavar='S,S,...',
help='cycle through the given line/point styles (o-)')
FLAGS.add_option_group(g)
-g = optparse.OptionGroup(FLAGS, 'Axis Options')
+g = optparse.OptionGroup(FLAGS, 'Plot Options')
g.add_option('-g', '--grid', default=False, action='store_true',
help='include a grid (False)')
g.add_option('-L', '--legend', metavar='[tl|cl|bl|tr|cr|br]',
@@ -256,11 +257,17 @@ def main(opts, args):
x = x or range(len(y))
+ if opts.every:
+ x = x[::opts.every]
+ y = y[::opts.every]
+
ax.plot(x, y, points[p], c=colors[c],
mec=colors[c], mfc=(1, 1, 1, 1), mew=1.,
label=label, **plot_kwargs)
if ey:
+ if opts.every:
+ ey = ey[::opts.every]
ax.errorbar(x, y, fmt=None, yerr=ey, ecolor=colors[c], **plot_kwargs)
for label, lines in read_input(args):

0 comments on commit ce93b85

Please sign in to comment.