8000 Restore bar log axis support accidentally removed in 2954 · matplotlib/matplotlib@843a865 · GitHub
[go: up one dir, main page]

Skip to content

Commit 843a865

Browse files
committed
Restore bar log axis support accidentally removed in 2954
svn path=/trunk/matplotlib/; revision=2955
1 parent 34c8990 commit 843a865

File tree

1 file changed

+56
-13
lines changed

1 file changed

+56
-13
lines changed

lib/matplotlib/axes.py

Lines changed: 56 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ def __init__(self, fig, rect,
402402
navigate_mode: the navigation toolbar button status: 'PAN', 'ZOOM', or None
403403
position: [left, bottom, width,height in Figure coords
404404
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
406406
title: the title string
407407
visible: a boolean - whether the axes is visible
408408
xlabel: the xlabel
@@ -415,7 +415,7 @@ def __init__(self, fig, rect,
415415
yscale: ['log' | 'linear']
416416
yticklabels: sequence of strings
417417
yticks: sequence of floats
418-
418+
419419
"""
420420
Artist.__init__(self)
421421
self._position = map(makeValue, rect)
@@ -2583,16 +2583,16 @@ def get_handles():
25832583
#### Specialized plotting
25842584

25852585

2586-
def bar(self, left, height, width=0.8, bottom=0,
2586+
def bar(self, left, height, width=0.8, bottom=None,
25872587
color=None, edgecolor=None, linewidth=None,
25882588
yerr=None, xerr=None, ecolor=None, capsize=3,
2589-
align='edge', orientation='vertical'
2589+
align='edge', orientation='vertical', log=False
25902590
):
25912591
"""
25922592
BAR(left, height, width=0.8, bottom=0,
25932593
color=None, edgecolor=None, linewidth=None,
25942594
yerr=None, xerr=None, ecolor=None, capsize=3,
2595-
align='edge', orientation='vertical')
2595+
align='edge', orientation='vertical', log=False)
25962596
25972597
Make a bar plot with rectangles bounded by
25982598
@@ -2631,6 +2631,9 @@ def bar(self, left, height, width=0.8, bottom=0,
26312631
26322632
orientation = 'vertical' | 'horizontal'
26332633
2634+
log = False | True - False (default) leaves the orientation
2635+
axis as-is; True sets it to log scale
2636+
26342637
For vertical bars, 'edge' aligns bars by their left edges in left,
26352638
while 'center' interprets these values as the x coordinates
26362639
of the bar centers.
@@ -2654,21 +2657,41 @@ def make_iterable(x):
26542657
return x
26552658

26562659
# make them safe to take len() of
2660+
_left = left
26572661
left = make_iterable(left)
26582662
height = make_iterable(height)
26592663
width = make_iterable(width)
2664+
_bottom = bottom
26602665
bottom = make_iterable(bottom)
26612666
linewidth = make_iterable(linewidth)
26622667

2668+
adjust_ylim = False
2669+
adjust_xlim = False
26632670
if orientation == 'vertical':
2671+
if log:
2672+
self.set_yscale('log')
26642673
# 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]
26652680
nbars = len(left)
26662681
if len(width) == 1:
26672682
width *= nbars
26682683
if len(bottom) == 1:
26692684
bottom *= nbars
26702685
elif orientation == 'horizontal':
2686+
if log:
2687+
self.set_xscale('log')
26712688
# 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]
26722695
nbars = len(bottom)
26732696
if len(left) == 1:
26742697
left *= nbars
@@ -2760,11 +2783,25 @@ def make_iterable(x):
27602783

27612784
self.hold(holdstate) # restore previous hold state
27622785

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)
27632800
self.autoscale_view()
27642801
return patches
27652802

27662803

2767-
def barh(self, bottom, width, height=0.8, left=0,
2804+
def barh(self, bottom, width, height=0.8, left=None,
27682805
color=None, edgecolor=None, linewidth=None,
27692806
xerr=None, yerr=None, ecolor=None, capsize=3,
27702807
align='edge'
@@ -4264,11 +4301,13 @@ def table(self, **kwargs):
42644301
#### Data analysis
42654302

42664303

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):
42694307
"""
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)
42724311
42734312
Compute the histogram of x. bins is either an integer number of
42744313
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,
42954334
width: the width of the bars. If None, automatically compute
42964335
the width.
42974336
4337+
log: if True, the histogram axis will be set to a log scale
4338+
42984339
kwargs are used to update the properties of the
42994340
hist Rectangles:
43004341
%(Rectangle)s
@@ -4303,9 +4344,11 @@ def hist(self, x, bins=10, normed=0, bottom=0,
43034344
n, bins = matplotlib.mlab.hist(x, bins, normed)
43044345
if width is None: width = 0.9*(bins[1]-bins[0])
43054346
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)
43074349
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)
43094352
else:
43104353
raise ValueError, 'invalid orientation: %s' % orientation
43114354
for p in patches:
@@ -5118,7 +5161,7 @@ def __init__(self, fig, *args, **kwargs):
51185161
PolarAxes.__init__(self, fig, [self.figLeft, self.figBottom, self.figW, self.figH], **kwargs)
51195162

51205163

5121-
5164+
51225165
artist.kwdocd['Axes'] = artist.kwdocd['Subplot'] = '\n'.join(artist.ArtistInspector(Axes).pprint_setters(leadingspace=12))
51235166
"""
51245167
# this is some discarded code I was using to find the minimum positive

0 commit comments

Comments
 (0)
0