@@ -402,7 +402,7 @@ def __init__(self, fig, rect,
402
402
navigate_mode: the navigation toolbar button status: 'PAN', 'ZOOM', or None
403
403
position: [left, bottom, width,height in Figure coords
404
404
sharex : an Axes instance to share the x-axis with
405
- sharey : an Axes instance to share the y-axis with
405
+ sharey : an Axes instance to share the y-axis with
406
406
title: the title string
407
407
visible: a boolean - whether the axes is visible
408
408
xlabel: the xlabel
@@ -415,7 +415,7 @@ def __init__(self, fig, rect,
415
415
yscale: ['log' | 'linear']
416
416
yticklabels: sequence of strings
417
417
yticks: sequence of floats
418
-
418
+
419
419
"""
420
420
Artist .__init__ (self )
421
421
self ._position = map (makeValue , rect )
@@ -2583,16 +2583,16 @@ def get_handles():
2583
2583
#### Specialized plotting
2584
2584
2585
2585
2586
- def bar (self , left , height , width = 0.8 , bottom = 0 ,
2586
+ def bar (self , left , height , width = 0.8 , bottom = None ,
2587
2587
color = None , edgecolor = None , linewidth = None ,
2588
2588
yerr = None , xerr = None , ecolor = None , capsize = 3 ,
2589
- align = 'edge' , orientation = 'vertical'
2589
+ align = 'edge' , orientation = 'vertical' , log = False
2590
2590
):
2591
2591
"""
2592
2592
BAR(left, height, width=0.8, bottom=0,
2593
2593
color=None, edgecolor=None, linewidth=None,
2594
2594
yerr=None, xerr=None, ecolor=None, capsize=3,
2595
- align='edge', orientation='vertical')
2595
+ align='edge', orientation='vertical', log=False )
2596
2596
2597
2597
Make a bar plot with rectangles bounded by
2598
2598
@@ -2631,6 +2631,9 @@ def bar(self, left, height, width=0.8, bottom=0,
2631
2631
2632
2632
orientation = 'vertical' | 'horizontal'
2633
2633
2634
+ log = False | True - False (default) leaves the orientation
2635
+ axis as-is; True sets it to log scale
2636
+
2634
2637
For vertical bars, 'edge' aligns bars by their left edges in left,
2635
2638
while 'center' interprets these values as the x coordinates
2636
2639
of the bar centers.
@@ -2654,21 +2657,41 @@ def make_iterable(x):
2654
2657
return x
2655
2658
2656
2659
# make them safe to take len() of
2660
+ _left = left
2657
2661
left = make_iterable (left )
2658
2662
height = make_iterable (height )
2659
2663
width = make_iterable (width )
2664
+ _bottom = bottom
2660
2665
bottom = make_iterable (bottom )
2661
2666
linewidth = make_iterable (linewidth )
2662
2667
2668
+ adjust_ylim = False
2669
+ adjust_xlim = False
2663
2670
if orientation == 'vertical' :
2671
+ if log :
2672
+ self .set_yscale ('log' )
2664
2673
# size width and bottom according to length of left
2674
+ if _bottom is None :
2675
+ if self .get_yscale () == 'log' :
2676
+ bottom = [1e-100 ]
2677
+ adjust_ylim = True
2678
+ else :
2679
+ bottom = [0 ]
2665
2680
nbars = len (left )
2666
2681
if len (width ) == 1 :
2667
2682
width *= nbars
2668
2683
if len (bottom ) == 1 :
2669
2684
bottom *= nbars
2670
2685
elif orientation == 'horizontal' :
2686
+ if log :
2687
+ self .set_xscale ('log' )
2671
2688
# size left and height according to length of bottom
2689
+ if _left is None :
2690
+ if self .get_xscale () == 'log' :
2691
+ left = [1e-100 ]
2692
+ adjust_xlim = True
2693
+ else :
2694
+ left = [0 ]
2672
2695
nbars = len (bottom )
2673
2696
if len (left ) == 1 :
2674
2697
left *= nbars
@@ -2760,11 +2783,25 @@ def make_iterable(x):
2760
2783
2761
2784
self .hold (holdstate ) # restore previous hold state
2762
2785
2786
+ if adjust_xlim :
2787
+ xmin , xmax = self .dataLim .intervalx ().get_bounds ()
2788
+ xmin = amin (w )
2789
+ if xerr is not None :
2790
+ xmin = xmin - amax (xerr )
2791
+ xmin = max (xmin * 0.9 , 1e-100 )
2792
+ self .dataLim .intervalx ().set_bounds (xmin , xmax )
2793
+ if adjust_ylim :
2794
+ ymin , ymax = self .dataLim .intervaly ().get_bounds ()
2795
+ ymin = amin (h )
2796
+ if yerr is not None :
2797
+ ymin = ymin - amax (yerr )
2798
+ ymin = max (ymin * 0.9 , 1e-100 )
2799
+ self .dataLim .intervaly ().set_bounds (ymin , ymax )
2763
2800
self .autoscale_view ()
2764
2801
return patches
2765
2802
2766
2803
2767
- def barh (self , bottom , width , height = 0.8 , left = 0 ,
2804
+ def barh (self , bottom , width , height = 0.8 , left = None ,
2768
2805
color = None , edgecolor = None , linewidth = None ,
2769
2806
xerr = None , yerr = None , ecolor = None , capsize = 3 ,
2770
2807
align = 'edge'
@@ -4264,11 +4301,13 @@ def table(self, **kwargs):
4264
4301
#### Data analysis
4265
4302
4266
4303
4267
- def hist (self , x , bins = 10 , normed = 0 , bottom = 0 ,
4268
- align = 'edge' , orientation = 'vertical' , width = None , ** kwargs ):
4304
+ def hist (self , x , bins = 10 , normed = 0 , bottom = None ,
4305
+ align = 'edge' , orientation = 'vertical' , width = None ,
4306
+ log = False , ** kwargs ):
4269
4307
"""
4270
- HIST(x, bins=10, normed=0, bottom=0,
4271
- align='edge', orientation='vertical', width=None, **kwargs)
4308
+ HIST(x, bins=10, normed=0, bottom=None,
4309
+ align='edge', orientation='vertical', width=None,
4310
+ log=False, **kwargs)
4272
4311
4273
4312
Compute the histogram of x. bins is either an integer number of
4274
4313
bins or a sequence giving the bins. x are the data to be binned.
@@ -4295,6 +4334,8 @@ def hist(self, x, bins=10, normed=0, bottom=0,
4295
4334
width: the width of the bars. If None, automatically compute
4296
4335
the width.
4297
4336
4337
+ log: if True, the histogram axis will be set to a log scale
4338
+
4298
4339
kwargs are used to update the properties of the
4299
4340
hist Rectangles:
4300
4341
%(Rectangle)s
@@ -4303,9 +4344,11 @@ def hist(self, x, bins=10, normed=0, bottom=0,
4303
4344
n , bins = matplotlib .mlab .hist (x , bins , normed )
4304
4345
if width is None : width = 0.9 * (bins [1 ]- bins [0 ])
4305
4346
if orientation == 'horizontal' :
4306
- patches = self .barh (bins , n , height = width , left = bottom , align = align )
4347
+ patches = self .barh (bins , n , height = width , left = bottom ,
4348
+ align = align , log = log )
4307
4349
elif orientation == 'vertical' :
4308
- patches = self .bar (bins , n , width = width , bottom = bottom , align = align )
4350
+ patches = self .bar (bins , n , width = width , bottom = bottom ,
4351
+ align = align , log = log )
4309
4352
else :
4310
4353
raise ValueError , 'invalid orientation: %s' % orientation
4311
4354
for p in patches :
@@ -5118,7 +5161,7 @@ def __init__(self, fig, *args, **kwargs):
5118
5161
PolarAxes .__init__ (self , fig , [self .figLeft , self .figBottom , self .figW , self .figH ], ** kwargs )
5119
5162
5120
5163
5121
-
5164
+
5122
5165
artist .kwdocd ['Axes' ] = artist .kwdocd ['Subplot' ] = '\n ' .join (artist .ArtistInspector (Axes ).pprint_setters (leadingspace = 12 ))
5123
5166
"""
5124
5167
# this is some discarded code I was using to find the minimum positive
0 commit comments