@@ -2548,16 +2548,16 @@ def get_handles():
25482548 #### Specialized plotting
25492549
25502550
2551- def bar (self , left , height , width = 0.8 , bottom = 0 ,
2551+ def bar (self , left , height , width = 0.8 , bottom = None ,
25522552 color = None , edgecolor = None , linewidth = None ,
25532553 yerr = None , xerr = None , ecolor = None , capsize = 3 ,
2554- align = 'edge' , orientation = 'vertical'
2554+ align = 'edge' , orientation = 'vertical' , log = False
25552555 ):
25562556 """
25572557 BAR(left, height, width=0.8, bottom=0,
25582558 color=None, edgecolor=None, linewidth=None,
25592559 yerr=None, xerr=None, ecolor=None, capsize=3,
2560- align='edge', orientation='vertical')
2560+ align='edge', orientation='vertical', log=False )
25612561
25622562 Make a bar plot with rectangles bounded by
25632563
@@ -2596,6 +2596,9 @@ def bar(self, left, height, width=0.8, bottom=0,
25962596
25972597 orientation = 'vertical' | 'horizontal'
25982598
2599+ log = False | True - False (default) leaves the orientation
2600+ axis as-is; True sets it to log scale
2601+
25992602 For vertical bars, 'edge' aligns bars by their left edges in left,
26002603 while 'center' interprets these values as the x coordinates
26012604 of the bar centers.
@@ -2619,21 +2622,41 @@ def make_iterable(x):
26192622 return x
26202623
26212624 # make them safe to take len() of
2625+ _left = left
26222626 left = make_iterable (left )
26232627 height = make_iterable (height )
26242628 width = make_iterable (width )
2629+ _bottom = bottom
26252630 bottom = make_iterable (bottom )
26262631 linewidth = make_iterable (linewidth )
26272632
2633+ adjust_ylim = False
2634+ adjust_xlim = False
26282635 if orientation == 'vertical' :
2636+ if log :
2637+ self .set_yscale ('log' )
26292638 # size width and bottom according to length of left
2639+ if _bottom is None :
2640+ if self .get_yscale () == 'log' :
2641+ bottom = [1e-100 ]
2642+ adjust_ylim = True
2643+ else :
2644+ bottom = [0 ]
26302645 nbars = len (left )
26312646 if len (width ) == 1 :
26322647 width *= nbars
26332648 if len (bottom ) == 1 :
26342649 bottom *= nbars
26352650 elif orientation == 'horizontal' :
2651+ if log :
2652+ self .set_xscale ('log' )
26362653 # size left and height according to length of bottom
2654+ if _left is None :
2655+ if self .get_xscale () == 'log' :
2656+ left = [1e-100 ]
2657+ adjust_xlim = True
2658+ else :
2659+ left = [0 ]
26372660 nbars = len (bottom )
26382661 if len (left ) == 1 :
26392662 left *= nbars
@@ -2725,11 +2748,25 @@ def make_iterable(x):
27252748
27262749 self .hold (holdstate ) # restore previous hold state
27272750
2751+ if adjust_xlim :
2752+ xmin , xmax = self .dataLim .intervalx ().get_bounds ()
2753+ xmin = amin (w )
2754+ if xerr is not None :
2755+ xmin = xmin - amax (xerr )
2756+ xmin = min (xmin , 1e-100 )
2757+ self .dataLim .intervalx ().set_bounds (xmin , xmax )
2758+ if adjust_ylim :
2759+ ymin , ymax = self .dataLim .intervaly ().get_bounds ()
2760+ ymin = amin (h )
2761+ if yerr is not None :
2762+ ymin = ymin - amax (yerr )
2763+ ymin = max (ymin , 1e-100 )
2764+ self .dataLim .intervaly ().set_bounds (ymin , ymax )
27282765 self .autoscale_view ()
27292766 return patches
27302767
27312768
2732- def barh (self , bottom , width , height = 0.8 , left = 0 ,
2769+ def barh (self , bottom , width , height = 0.8 , left = None ,
27332770 color = None , edgecolor = None , linewidth = None ,
27342771 xerr = None , yerr = None , ecolor = None , capsize = 3 ,
27352772 align = 'edge'
@@ -4229,11 +4266,13 @@ def table(self, **kwargs):
42294266 #### Data analysis
42304267
42314268
4232- def hist (self , x , bins = 10 , normed = 0 , bottom = 0 ,
4233- align = 'edge' , orientation = 'vertical' , width = None , ** kwargs ):
4269+ def hist (self , x , bins = 10 , normed = 0 , bottom = None ,
4270+ align = 'edge' , orientation = 'vertical' , width = None ,
4271+ log = False , ** kwargs ):
42344272 """
4235- HIST(x, bins=10, normed=0, bottom=0,
4236- align='edge', orientation='vertical', width=None, **kwargs)
4273+ HIST(x, bins=10, normed=0, bottom=None,
4274+ align='edge', orientation='vertical', width=None,
4275+ log=False, **kwargs)
42374276
42384277 Compute the histogram of x. bins is either an integer number of
42394278 bins or a sequence giving the bins. x are the data to be binned.
@@ -4260,6 +4299,8 @@ def hist(self, x, bins=10, normed=0, bottom=0,
42604299 width: the width of the bars. If None, automatically compute
42614300 the width.
42624301
4302+ log: if True, the histogram axis will be set to a log scale
4303+
42634304 kwargs are used to update the properties of the
42644305 hist Rectangles:
42654306%(Rectangle)s
@@ -4268,9 +4309,11 @@ def hist(self, x, bins=10, normed=0, bottom=0,
42684309 n , bins = matplotlib .mlab .hist (x , bins , normed )
42694310 if width is None : width = 0.9 * (bins [1 ]- bins [0 ])
42704311 if orientation == 'horizontal' :
4271- patches = self .barh (bins , n , height = width , left = bottom , align = align )
4312+ patches = self .barh (bins , n , height = width , left = bottom ,
4313+ align = align , log = log )
42724314 elif orientation == 'vertical' :
4273- patches = self .bar (bins , n , width = width , bottom = bottom , align = align )
4315+ patches = self .bar (bins , n , width = width , bottom = bottom ,
4316+ align = align , log = log )
42744317 else :
42754318 raise ValueError , 'invalid orientation: %s' % orientation
42764319 for p in patches :
0 commit comments