shithub: aubio

ref: a72f3f19a62e279673b902525e5f4340f0c4c139
dir: /tests/demo/bench/pitch/bench-pitch-plot-isolated/

View raw version
#! /usr/bin/python

if __name__ == '__main__':
  import sys, Gnuplot
  from aubio.gnuplot import gnuplot_create
  from aubio.txtfile import read_datafile
  from aubio.plot.keyboard import draw_keyboard
  lines = []
  titles = []
  for file in range(len(sys.argv)-1):
    l = read_datafile(sys.argv[file+1])
    notes, score = [],[]
    for i in range(len(l)):
      notes.append(l[i][0])
      score.append(l[i][2])
    lines.append(Gnuplot.Data(notes,score,
      with='linespoints',
      title=sys.argv[file+1].split('.')[-1]))
    titles.append(sys.argv[file+1].split('.')[-1])
  blacks,whites = draw_keyboard(firstnote = notes[0], lastnote = notes[-1], 
    y0= 40, y1 = 50)

  g = gnuplot_create(sys.argv[file+1].split('.')[-3],'ps')
  #g = gnuplot_create('','')
  #g = gnuplot_create('/tmp/test','eps')
  g('set yrange [40:100]')
  #g('set xrange [%f:%f]' % (notes[0],notes[-1]+60))
  g('set size 0.5')
  g('set key outside')

  g('set border 3')
  g('set xtics nomirror')
  g('set ytics nomirror')
  multiplot = 1
  oplots = lines
  g('set size 1,2')
  if multiplot:
    height = 2.
    g('set lmargin 10')
    #g('set rmargin 15')
    g('set multiplot')
    g('set yrange [50:100]')
    g('set xrange [%f:%f]' % (notes[0],notes[-1]))
    g('set xtics %f,12' % notes[0])
    g('set nokey')
    for i in range(len(oplots)):
      g.ylabel(titles[i])
      g('set size %f,%f' % (1.,height*.85/float(len(oplots))))
      g('set origin 0,%f' % (height*(.15+.85*float(len(oplots)-i-1)/float(len(oplots)))))
      g.plot(oplots[i])
    g('set title "Raw pitch accuracy (%) against midi note numbers"')
    g('set noxtics')
    g('set noytics')
    g('set size %f,%f' % (1.,.15*height))
    g('set origin 0,%f' % 0)
    g('set yrange [40:50]')
    g('set xrange [%f:%f]' % (notes[0],notes[-1]))
    g.xlabel('')
    g.ylabel('')
    g.plot(whites,blacks)
    g('unset multiplot')
  else:
    g.plot(whites,blacks,*lines)