fix timelines and plot sizes in onset and pitch
authorPaul Brossier <piem@altern.org>
Thu, 13 Jul 2006 13:48:24 +0000 (13:48 +0000)
committerPaul Brossier <piem@altern.org>
Thu, 13 Jul 2006 13:48:24 +0000 (13:48 +0000)
fix timelines and plot sizes in onset and pitch

python/aubio/task/onset.py
python/aubio/task/pitch.py

index 4103246258fc950b217a9c88c44a036e8f37d1b1..20a1282ea7b1460a150d09d5d583970e3dd89aa2 100644 (file)
@@ -144,7 +144,7 @@ class taskonset(task):
                import re
                # prepare the plot
                g = gnuplot_create(outplot=outplot, extension=extension)
-               
+               g('set title \'%s\'' % (re.sub('.*/','',self.input)))
                if spectro:
                        g('set size %f,%f' % (xsize,1.3*ysize) )
                else:
@@ -154,23 +154,6 @@ class taskonset(task):
                # hack to align left axis
                g('set lmargin 3')
                g('set rmargin 6')
-               g('set tmargin 0')
-               g('set format x ""')
-               g('set format y "%3e"')
-               g('set noytics')
-
-               for i in range(len(oplots)):
-                       # plot onset detection functions
-                       g('set size %f,%f' % (xsize,0.7*ysize/(len(oplots))))
-                       g('set origin 0,%f' % ((len(oplots)-float(i)-1)*0.7*ysize/(len(oplots))))
-                       g('set xrange [0:%f]' % (self.lenofunc*self.params.step))
-                       g('set nokey')
-                       g('set yrange [0:%f]' % (1.1*oplots[i][2]))
-                       g('set y2tics ("0" 0, "%d" %d)' % (round(oplots[i][2]),round(oplots[i][2])))
-                       g.ylabel(oplots[i][1])
-                       if i == len(oplots)-1:
-                               g.xlabel('time (s)',offset=(0,0.7))
-                       g.plot(*oplots[i][0])
 
                if spectro:
                        import Gnuplot
@@ -187,36 +170,53 @@ class taskonset(task):
                        g('set rmargin 0')
                        g('set tmargin 0')
                        g('set palette rgbformulae -25,-24,-32')
-                       g.xlabel('')
+                       g.xlabel('time (s)',offset=(0,1.))
                        g.ylabel('freq (Hz)')
+                       g('set origin 0,%f' % (1.0*ysize) ) 
+                       g('set format x "%1.1f"')
                        #if log:
                        #       g('set yrange [%f:%f]' % (max(10,minf),maxf))
                        #       g('set log y')
                        g.splot(Gnuplot.GridData(data,time,freq, binary=1, title=''))
-                       g('set lmargin 3')
-                       g('set rmargin 6')
-                       g('set origin 0,%f' % (1.0*ysize) ) 
-                       g('set format x "%1.1f"')
-                       g.xlabel('time (s)',offset=(0,1.))
                else:
                        # plot waveform and onsets
+                       time,data = audio_to_array(self.input)
+                       wplot = [make_audio_plot(time,data)] + wplot
                        g('set origin 0,%f' % (0.7*ysize) )
-                       g.xlabel('time (s)',offset=(0,0.7))
+                       g('set size %f,%f' % (xsize,0.3*ysize))
                        g('set format y "%1f"')
+                       g('set xrange [0:%f]' % max(time)) 
+                       g('set yrange [-1:1]') 
+                       g('set noytics')
+                       g('set y2tics -1,1')
+                       g.xlabel('time (s)',offset=(0,0.7))
+                       g.ylabel('amplitude')
+                       g.plot(*wplot)
 
-               g('set size %f,%f' % (1.*xsize, 0.3*ysize))
-               g('set title \'%s %s\'' % (re.sub('.*/','',self.input),self.title))
-               g('set tmargin 2')
-               # audio data
-               time,data = audio_to_array(self.input)
-               wplot = [make_audio_plot(time,data)] + wplot
-               g('set y2tics -1,1')
-
-               g('set xrange [0:%f]' % max(time)) 
-               g('set yrange [-1:1]') 
-               g.ylabel('amplitude')
-               g.plot(*wplot)
-               
-               g('unset multiplot')
+               # default settings for next plots
+               g('unset title')
+               g('set format x ""')
+               g('set format y "%3e"')
+               g('set tmargin 0')
+               g.xlabel('')
 
+               N = len(oplots)
+               y = 0.7*ysize # the vertical proportion of the plot taken by onset functions
+               delta = 0.035 # the constant part of y taken by last plot label and data
+               for i in range(N):
+                       # plot onset detection functions
+                       g('set size %f,%f' % ( xsize, (y-delta)/N))
+                       g('set origin 0,%f' % ((N-i-1)*(y-delta)/N + delta ))
+                       g('set nokey')
+                       g('set xrange [0:%f]' % (self.lenofunc*self.params.step))
+                       g('set yrange [0:%f]' % (1.1*oplots[i][2]))
+                       g('set y2tics ("0" 0, "%d" %d)' % (round(oplots[i][2]),round(oplots[i][2])))
+                       g.ylabel(oplots[i][1])
+                       if i == N-1:
+                               g('set size %f,%f' % ( xsize, (y-delta)/N + delta ) )
+                               g('set origin 0,0')
+                               g.xlabel('time (s)', offset=(0,0.7))
+                               g('set format x')
+                       g.plot(*oplots[i][0])
 
+               g('unset multiplot')
index 4b19b657791b645baf8a0733bf3731810e23b6d1..d8ea1e242f5336ddc80b210927261143981af772 100644 (file)
@@ -161,13 +161,10 @@ class taskpitch(task):
                titles.append(self.params.pitchmode)
 
                        
-       def plotplot(self,wplot,oplots,titles,outplot=None,multiplot = 1, midi = 1, truth = 1):
-               from aubio.gnuplot import gnuplot_init, audio_to_array, make_audio_plot
+       def plotplot(self,wplot,oplots,titles,outplot=None,extension=None,xsize=1.,ysize=1.,multiplot = 1, midi = 1, truth = 1):
+               from aubio.gnuplot import gnuplot_create , audio_to_array, make_audio_plot
                import re
                import Gnuplot
-               # audio data
-               time,data = audio_to_array(self.input)
-               f = make_audio_plot(time,data)
 
                # check if ground truth exists
                if truth:
@@ -176,32 +173,35 @@ class taskpitch(task):
                                oplots = [Gnuplot.Data(timet,pitcht,with='lines',
                                        title='ground truth')] + oplots
 
-               t = Gnuplot.Data(0,0,with='impulses') 
-
-               g = gnuplot_init(outplot)
+               g = gnuplot_create(outplot=outplot, extension=extension)
                g('set title \'%s\'' % (re.sub('.*/','',self.input)))
+               g('set size %f,%f' % (xsize,ysize) )
                g('set multiplot')
                # hack to align left axis
                g('set lmargin 4')
                g('set rmargin 4')
-               # plot waveform and onsets
-               g('set size 1,0.3')
-               g('set ytics 10')
-               g('set origin 0,0.7')
+    # plot waveform
+               time,data = audio_to_array(self.input)
+               wplot = [make_audio_plot(time,data)]
+               g('set origin 0,%f' % (0.7*ysize) )
+               g('set size %f,%f' % (xsize,0.3*ysize))
+               #g('set format y "%1f"')
                g('set xrange [0:%f]' % max(time)) 
                g('set yrange [-1:1]') 
                g('set noytics')
                g('set y2tics -1,1')
-               g.xlabel('time (s)',offset=(0,0.8))
+               g.xlabel('time (s)',offset=(0,0.7))
                g.ylabel('amplitude')
-               g.plot(f)
-               g('unset title')
-               # plot onset detection function
+               g.plot(*wplot)
 
+               # default settings for next plots
+               g('unset title')
+               g('set format x ""')
+               g('set format y "%3e"')
+               g('set tmargin 0')
+               g.xlabel('')
+               g('set noclip one') 
 
-               g('set size 1,0.7')
-               g('set origin 0,0')
-               g('set xrange [0:%f]' % max(time))
                if not midi:
                        g('set log y')
                        #g.xlabel('time (s)')
@@ -211,21 +211,26 @@ class taskpitch(task):
                        g.ylabel('midi')
                        g('set yrange [%f:%f]' % (aubio_freqtomidi(self.params.pitchmin), aubio_freqtomidi(self.params.pitchmax)))
                        g('set y2tics %f,%f' % (round(aubio_freqtomidi(self.params.pitchmin)+.5),12))
-               g('set key right top')
-               g('set noclip one') 
-               g('set format x ""')
+               
                if multiplot:
-                       g('set tmargin 0')
-                       for i in range(len(oplots)):
-                               # plot onset detection functions
-                               g('set size 1,%f' % (0.7/(len(oplots))))
-                               g('set origin 0,%f' % ((len(oplots)-float(i)-1)*0.7/(len(oplots))))
-                               g('set xrange [0:%f]' % max(time))
+                       N = len(oplots)
+                       y = 0.7*ysize # the vertical proportion of the plot taken by onset functions
+                       delta = 0.035 # the constant part of y taken by last plot label and data
+                       for i in range(N):
+                               # plot pitch detection functions
+                               g('set size %f,%f' % ( xsize, (y-delta)/N))
+                               g('set origin 0,%f' % ((N-i-1)*(y-delta)/N + delta ))
                                g('set nokey')
+                               g('set xrange [0:%f]' % max(time))
                                g.ylabel(titles[i])
-                               g.xlabel('')
+                               if i == N-1:
+                                       g('set size %f,%f' % (xsize, (y-delta)/N + delta ) )
+                                       g('set origin 0,0')
+                                       g.xlabel('time (s)', offset=(0,0.7))
+                                       g('set format x')
                                g.plot(oplots[i])
                else:
+                       g('set key right top')
                        g.plot(*oplots)
                g('unset multiplot')