@@ -573,7 +573,7 @@ def plot_new(self, offset="freq", width="amp", scale=None):
573573 # "color": None,
574574 # "y_offset": 0,
575575
576- fig = plt .figure (figsize = (8 , 2 ) )
576+ fig = plt .figure () # figsize=(8, 2)
577577 ax = fig .add_subplot (1 , 1 , 1 )
578578 cmap = plt .get_cmap ("Set1" )
579579
@@ -608,7 +608,6 @@ def warp_width(value, scale=None, width_min=2, width_max=4):
608608 ret = pam .linlin (
609609 value , widths .min (), widths .max (), width_min , width_max
610610 )
611- print (value , ret )
612611 return ret
613612
614613 offsets = warp_offset (offsets )
@@ -637,20 +636,30 @@ def warp_width(value, scale=None, width_min=2, width_max=4):
637636 y_min = min (offsets .min (), y_min )
638637 y_max = max (offsets .max (), y_max )
639638
640- x_lim = (x_max - x_min ) * 0.01
641- ax .set_xlim (x_min - x_lim , x_max + x_lim )
639+ # x_lim = (x_max - x_min) * 0.01
640+ # ax.set_xlim(x_min - x_lim, x_max + x_lim)
642641 # y_lim = (y_max - y_min) * 0.1
643642 # axes.set_ylim(y_min - y_lim, y_max + y_lim)
644643
644+ MAX_LEGEND_NCOLS = 5
645+
645646 # test
646- ax .legend (handles = patches , loc = "best" )
647+ ax .legend (
648+ handles = patches ,
649+ loc = "lower left" ,
650+ mode = "expand" ,
651+ bbox_to_anchor = (0.0 , 1.02 , 1.0 , 0.102 ),
652+ borderaxespad = 0 ,
653+ ncol = min (len (patches ), MAX_LEGEND_NCOLS ),
654+ )
647655 ax .grid ()
648- ax .set_title ("Timeline" )
649656 ax .set_xlabel ("time [s]" )
650657
651658 if offset == "freq" :
652659 ax .set_yscale ("log" )
653660 ax .set_ylabel ("frequency [Hz]" )
661+
662+ # TODO perhaps we also could want mel?
654663 secax = ax .secondary_yaxis (
655664 location = "right" , functions = (pam .cps_to_midi , pam .midi_to_cps )
656665 )
@@ -664,22 +673,20 @@ def warp_width(value, scale=None, width_min=2, width_max=4):
664673 ax .set_ylabel ("amplitude" )
665674
666675 def safe_amp_to_db (amp ):
667- return pam . amp_to_db (amp ) if amp > 0 else - 90
676+ return np . where (amp > 0 , pam . amp_to_db ( amp ), - 90 )
668677
669678 secax = ax .secondary_yaxis (
670679 location = "right" , functions = (safe_amp_to_db , pam .db_to_amp )
671680 )
672681 secax .set_ylabel ("level [dB]" )
673682 secax .yaxis .set_major_locator (
674- ticker .MaxNLocator (nbins = "auto" , steps = [1 , 2 , 4 , 5 , 10 ], integer = True )
683+ ticker .MaxNLocator (nbins = "auto" , steps = [1 , 2 , 4 , 5 , 10 ])
675684 )
676685 secax .yaxis .set_major_formatter (lambda x , pos : str (int (x )))
677686 else :
678687 ax .set_ylabel (offset )
679688
680- ax .autoscale (enable = True , axis = True , tight = True )
681- # axes.margins(0.05)
682-
689+ ax .autoscale (enable = True )
683690 fig .tight_layout ()
684691
685692 # TODO Idea: convention to order the Synth Params by most probalbe usage
0 commit comments