Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 62717fb

Browse files
committed
fixed a bar units bug
svn path=/trunk/matplotlib/; revision=3844
1 parent c7d600f commit 62717fb

8 files changed

Lines changed: 67 additions & 18 deletions

File tree

API_CHANGES

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
Made skiprows=1 the default on csv2rec
2+
13
The gd and paint backends have been deleted.
24

35
The errorbar method and function now accept additional kwargs

CHANGELOG

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
2007-09-12 Fixed a Axes.bar unit bug - JDH
2+
3+
2007-09-10 Made skiprows=1 the default on csv2rec - JDH
4+
15
2007-09-09 Split out the plotting part of pylab and put it in
26
pyplot.py; removed numerix from the remaining pylab.py,
37
which imports everything from pyplot.py. The intention

examples/units/bar_demo2.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
"""
2+
plot using a variety of cm vs inches conversions. The example shows
3+
how default unit instrospection works (ax1), how various keywords can
4+
be used to set the x and y units to override the defaults (ax2, ax3,
5+
ax4) and how one can set the xlimits using scalars (ax3, current units
6+
assumed) or units (conversions applied to get the numbers to current
7+
units)
8+
9+
"""
10+
from basic_units import cm, inch
11+
from pylab import figure, show, nx
12+
13+
cms = cm *nx.arange(0, 10, 2)
14+
bottom=0*cm
15+
width=0.8*cm
16+
17+
fig = figure()
18+
19+
ax1 = fig.add_subplot(2,2,1)
20+
ax1.bar(cms, cms, bottom=bottom)
21+
22+
ax2 = fig.add_subplot(2,2,2)
23+
ax2.bar(cms, cms, bottom=bottom, width=width, xunits=cm, yunits=inch)
24+
25+
ax3 = fig.add_subplot(2,2,3)
26+
ax3.bar(cms, cms, bottom=bottom, width=width, xunits=inch, yunits=cm)
27+
ax3.set_xlim(3, 6) # scalars are interpreted in current units
28+
29+
ax4 = fig.add_subplot(2,2,4)
30+
ax4.bar(cms, cms, bottom=bottom, width=width, xunits=inch, yunits=inch)
31+
#fig.savefig('simple_conversion_plot.png')
32+
ax4.set_xlim(3*cm, 6*cm) # cm are converted to inches
33+
34+
show()

lib/matplotlib/artist.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def __init__(self):
5151
self._remove_method = None
5252

5353
def remove(self):
54-
'''
54+
"""
5555
Remove the artist from the figure if possible. The effect will not
5656
be visible until the figure is redrawn, e.g., with ax.draw_idle().
5757
Call ax.relim() to update the axes limits if desired.
@@ -60,7 +60,7 @@ def remove(self):
6060
was added to axes with autolim=True.
6161
6262
Note: there is no support for removing the artist's legend entry.
63-
'''
63+
"""
6464

6565
# There is no method to set the callback. Instead the parent should set
6666
# the _remove_method attribute directly. This would be a protected

lib/matplotlib/axes.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,23 +1198,27 @@ def _get_verts_in_data_coords(self, trans, xys):
11981198
def _process_unit_info(self, xdata=None, ydata=None, kwargs=None):
11991199
'look for unit kwargs and update the axis instances as necessary'
12001200

1201-
if self.xaxis is None or self.xaxis is None: return
1202-
1201+
if self.xaxis is None or self.yaxis is None: return
12031202

1203+
#print 'processing', self.get_geometry()
12041204
if xdata is not None:
12051205
self.xaxis.update_units(xdata)
1206+
#print '\tset from xdata', self.xaxis.units
12061207

12071208
if ydata is not None:
12081209
self.yaxis.update_units(ydata)
1210+
#print '\tset from ydata', self.yaxis.units
12091211

12101212
# process kwargs 2nd since these will override default units
12111213
if kwargs is not None:
12121214
xunits = kwargs.pop( 'xunits', self.xaxis.units)
12131215
if xunits!=self.xaxis.units:
1216+
#print '\tkw setting xunits', xunits
12141217
self.xaxis.set_units(xunits)
12151218

12161219
yunits = kwargs.pop('yunits', self.yaxis.units)
12171220
if yunits!=self.yaxis.units:
1221+
#print '\tkw setting yunits', yunits
12181222
self.yaxis.set_units(yunits)
12191223

12201224
def in_axes(self, xwin, ywin):
@@ -3114,10 +3118,12 @@ def make_iterable(x):
31143118
else:
31153119
raise ValueError, 'invalid orientation: %s' % orientation
31163120

3117-
left = npy.asarray(left)
3118-
height = npy.asarray(height)
3119-
width = npy.asarray(width)
3120-
bottom = npy.asarray(bottom)
3121+
3122+
# do not convert to array here as unit info is lost
3123+
#left = npy.asarray(left)
3124+
#height = npy.asarray(height)
3125+
#width = npy.asarray(width)
3126+
#bottom = npy.asarray(bottom)
31213127

31223128
if len(linewidth) == 1: linewidth = linewidth * nbars
31233129

@@ -3161,14 +3167,14 @@ def make_iterable(x):
31613167
# lets do some conversions now
31623168
if self.xaxis is not None:
31633169
xconv = self.xaxis.converter
3164-
if ( xconv ):
3170+
if xconv is not None:
31653171
units = self.xaxis.get_units()
31663172
left = xconv.convert( left, units )
31673173
width = xconv.convert( width, units )
31683174

31693175
if self.yaxis is not None:
31703176
yconv = self.yaxis.converter
3171-
if ( yconv ):
3177+
if yconv is not None :
31723178
units = self.yaxis.get_units()
31733179
bottom = yconv.convert( bottom, units )
31743180
height = yconv.convert( height, units )
@@ -3208,12 +3214,14 @@ def make_iterable(x):
32083214

32093215
if xerr is not None or yerr is not None:
32103216
if orientation == 'vertical':
3211-
x = left + 0.5*width
3212-
y = bottom + height
3217+
# using list comps rather than arrays to preserve unit info
3218+
x = [l+0.5*w for l, w in zip(left, width)]
3219+
y = [b+h for b,h in zip(bottom, height)]
32133220

32143221
elif orientation == 'horizontal':
3215-
x = left + width
3216-
y = bottom + 0.5*height
3222+
# using list comps rather than arrays to preserve unit info
3223+
x = [l+w for l,w in zip(left, width)]
3224+
y = [b+0.5*h for b,h in zip(bottom, height)]
32173225

32183226
self.errorbar(
32193227
x, y,

lib/matplotlib/axis.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,7 @@ def convert_units(self, x):
828828
return x
829829

830830
ret = self.converter.convert(x, self.units)
831-
#print 'convert_units converting: units=%s, converter=%s, in=%s, out=%s'%(self.units, self.converter, x, ret)
831+
#print 'convert_units converting: axis=%s, units=%s, converter=%s, in=%s, out=%s'%(self, self.units, self.converter, x, ret)
832832
return ret
833833

834834
def set_units(self, u):

lib/matplotlib/mlab.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,9 +1253,9 @@ def load(fname,comments='#',delimiter=None, converters=None,skiprows=0,
12531253
if r==1 or c==1:
12541254
X.shape = max(r,c),
12551255
if unpack: return X.transpose()
1256-
return X
1256+
else: return X
12571257

1258-
def csv2rec(fname, comments='#', skiprows=0, checkrows=5, delimiter=',',
1258+
def csv2rec(fname, comments='#', skiprows=1, checkrows=5, delimiter=',',
12591259
converterd=None, names=None, missing=None):
12601260
"""
12611261
Load data from comma/space/tab delimited file in fname into a

lib/matplotlib/patches.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ def __init__(self,
7777
if len(kwargs): artist.setp(self, **kwargs)
7878
__init__.__doc__ = cbook.dedent(__init__.__doc__) % artist.kwdocd
7979

80+
81+
8082
def contains(self, mouseevent):
8183
"""Test whether the mouse event occurred in the patch.
8284
@@ -347,7 +349,6 @@ def get_verts(self):
347349
Return the vertices of the rectangle
348350
"""
349351
x, y = self.xy
350-
351352
left, right = self.convert_xunits((x, x + self.width))
352353
bottom, top = self.convert_yunits((y, y + self.height))
353354

0 commit comments

Comments
 (0)