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

Skip to content

Commit 6d00dbf

Browse files
committed
Merged revisions 3909-3924 via svnmerge from
http://matplotlib.svn.sf.net/svnroot/matplotlib/trunk/matplotlib ........ r3910 | jrevans | 2007-10-03 18:23:48 -0400 (Wed, 03 Oct 2007) | 4 lines Moved a couple of routines from the Agg version of the FigureCanvas to the base qt version where they belong. Added a couple of overloaded qt methods that should be there and reduce having to inherit when embedding in another QWidget. ........ r3911 | jrevans | 2007-10-03 19:05:30 -0400 (Wed, 03 Oct 2007) | 3 lines Removed an erroneous print statment in backend_qt.py. Added a feature to keep track of axes inversions. ........ r3916 | sameerd | 2007-10-04 17:39:07 -0400 (Thu, 04 Oct 2007) | 3 lines Fix for "NameError: global name 'ones' is not defined" ........ r3917 | jrevans | 2007-10-04 18:13:18 -0400 (Thu, 04 Oct 2007) | 5 lines axes.py: Reverted get/set xlim/ylim methods to original state Added get/set xbound/ybound to handle axes inversion maintenance Removed inverted axes flags patches.py: Added some logic to xform an Ellipse angle as per the Ellipse's transformation. ........ r3918 | efiring | 2007-10-05 02:18:25 -0400 (Fri, 05 Oct 2007) | 2 lines Minor cleanup of arguments and docstring in contour ........ r3919 | efiring | 2007-10-05 02:58:15 -0400 (Fri, 05 Oct 2007) | 2 lines Tweaked automatic contour level calculation ........ r3920 | jrevans | 2007-10-05 12:29:17 -0400 (Fri, 05 Oct 2007) | 2 lines Fixed a typo in the Ellipse code that was causing the ellipse angle to go in the wrong direction. When I was testing I had forgotten to turn off the axes inversion test. ........ r3921 | jrevans | 2007-10-05 13:01:36 -0400 (Fri, 05 Oct 2007) | 2 lines Fixed an error in calculating the mid-point of a bar since the values are now lists and not arrays, they need to be iterated to perform the arithmetic. ........ r3923 | dsdale | 2007-10-05 14:56:10 -0400 (Fri, 05 Oct 2007) | 1 line remove generator expressions from texmanager and mpltraits ........ svn path=/branches/transforms/; revision=3925
1 parent 8baa717 commit 6d00dbf

7 files changed

Lines changed: 123 additions & 104 deletions

File tree

CHANGELOG

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
2007-10-05 remove generator expressions from texmanager and mpltraits.
2+
generator expressions are not supported by python-2.3 - DSD
3+
14
2007-10-01 Made matplotlib.use() raise an exception if called after
25
backends has been imported.
36

examples/simple_plot.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,6 @@
1717
#savefig('simple_plot.png')
1818
savefig('simple_plot')
1919

20+
axes().set_xlim(5, -5)
21+
2022
show()

lib/matplotlib/axes.py

Lines changed: 93 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -844,9 +844,9 @@ def apply_aspect(self):
844844
return
845845

846846

847-
xmin,xmax = self.get_xlim()
847+
xmin,xmax = self.get_xbound()
848848
xsize = max(math.fabs(xmax-xmin), 1e-30)
849-
ymin,ymax = self.get_ylim()
849+
ymin,ymax = self.get_ybound()
850850
ysize = max(math.fabs(ymax-ymin), 1e-30)
851851

852852
l,b,w,h = self.get_position(original=True).bounds
@@ -895,14 +895,14 @@ def apply_aspect(self):
895895
yc = 0.5*(ymin+ymax)
896896
y0 = yc - Ysize/2.0
897897
y1 = yc + Ysize/2.0
898-
self.set_ylim((y0, y1))
898+
self.set_ybound((y0, y1))
899899
#print 'New y0, y1:', y0, y1
900900
#print 'New ysize, ysize/xsize', y1-y0, (y1-y0)/xsize
901901
else:
902902
xc = 0.5*(xmin+xmax)
903903
x0 = xc - Xsize/2.0
904904
x1 = xc + Xsize/2.0
905-
self.set_xlim((x0, x1))
905+
self.set_xbound((x0, x1))
906906
#print 'New x0, x1:', x0, x1
907907
#print 'New xsize, ysize/xsize', x1-x0, ysize/(x1-x0)
908908

@@ -1186,24 +1186,20 @@ def autoscale_view(self, tight=False, scalex=True, scaley=True):
11861186
len(self.lines)==0 and
11871187
len(self.patches)==0)):
11881188

1189-
if scalex: self.set_xlim(self.dataLim.intervalx().get_bounds())
1189+
if scalex: self.set_xbound(self.dataLim.intervalx().get_bounds())
11901190

1191-
if scaley: self.set_ylim(self.dataLim.intervaly().get_bounds())
1191+
if scaley: self.set_ybound(self.dataLim.intervaly().get_bounds())
11921192
return
11931193

11941194
if scalex:
1195-
xl = self.get_xlim()
1195+
xl = self.get_xbound()
11961196
XL = self.xaxis.get_major_locator().autoscale()
1197-
if xl[1] < xl[0]:
1198-
XL = XL[::-1]
1199-
self.set_xlim(XL)
1197+
self.set_xbound(XL)
12001198
if scaley:
12011199
ylocator = self.yaxis.get_major_locator()
1202-
yl = self.get_ylim()
1200+
yl = self.get_ybound()
12031201
YL = ylocator.autoscale()
1204-
if yl[1] < yl[0]:
1205-
YL = YL[::-1]
1206-
self.set_ylim(YL)
1202+
self.set_ybound(YL)
12071203

12081204
#### Drawing
12091205
def draw(self, renderer=None, inframe=False):
@@ -1427,13 +1423,46 @@ def set_axis_bgcolor(self, color):
14271423

14281424
### data limits, ticks, tick labels, and formatting
14291425

1430-
def invert_xaxis(self, invert=True):
1431-
"Invert the x-axis if 'invert' is True."
1432-
self._invertedx = invert
1426+
def invert_xaxis(self):
1427+
"Invert the x-axis."
1428+
left, right = self.get_xlim()
1429+
self.set_xlim(right, left)
14331430

14341431
def xaxis_inverted(self):
14351432
'Returns True if the x-axis is inverted.'
1436-
return self._invertedx
1433+
left, right = self.get_xlim()
1434+
return right < left
1435+
1436+
def get_xbound(self):
1437+
"Returns the x-axis numerical bounds in the form of lowerBound < upperBound"
1438+
left, right = self.get_xlim()
1439+
if left < right:
1440+
return left, right
1441+
else:
1442+
return right, left
1443+
1444+
def set_xbound(self, lower=None, upper=None):
1445+
"""Set the lower and upper numerical bounds of the x-axis.
1446+
This method will honor axes inversion regardless of parameter order.
1447+
"""
1448+
if upper is None and iterable(lower):
1449+
lower,upper = lower
1450+
1451+
old_lower,old_upper = self.get_xbound()
1452+
1453+
if lower is None: lower = old_lower
1454+
if upper is None: upper = old_upper
1455+
1456+
if self.xaxis_inverted():
1457+
if lower < upper:
1458+
self.set_xlim(upper, lower)
1459+
else:
1460+
self.set_xlim(lower, upper)
1461+
else:
1462+
if lower < upper:
1463+
self.set_xlim(lower, upper)
1464+
else:
1465+
self.set_xlim(upper, lower)
14371466

14381467
def get_xlim(self):
14391468
"""Get the x-axis range [xmin, xmax]
@@ -1483,21 +1512,9 @@ def set_xlim(self, xmin=None, xmax=None, emit=True, **kwargs):
14831512
if xmin is None: xmin = old_xmin
14841513
if xmax is None: xmax = old_xmax
14851514

1486-
# provided for backwards compatability
1487-
if ( xmax < xmin ):
1488-
# swap the values so that xmin < xmax and set inverted flag
1489-
tmp = xmin
1490-
xmin = xmax
1491-
xmax = tmp
1492-
self.invert_xaxis( True )
1493-
1494-
if ( self._invertedx ):
1495-
xmax, xmin = mtransforms.nonsingular(xmax, xmin, increasing=False)
1496-
self.viewLim.intervalx = (xmax, xmin)
1497-
else:
1498-
xmin, xmax = mtransforms.nonsingular(xmin, xmax, increasing=False)
1499-
self.viewLim.intervalx = (xmin, xmax)
1500-
1515+
xmax, xmin = mtransforms.nonsingular(xmax, xmin, increasing=False)
1516+
self.viewLim.intervalx = (xmin, xmax)
1517+
15011518
if emit:
15021519
self.callbacks.process('xlim_changed', self)
15031520
# Call all of the other x-axes that are shared with this one
@@ -1566,13 +1583,46 @@ def set_xticklabels(self, labels, fontdict=None, **kwargs):
15661583
return self.xaxis.set_ticklabels(labels, fontdict, **kwargs)
15671584
set_xticklabels.__doc__ = cbook.dedent(set_xticklabels.__doc__) % martist.kwdocd
15681585

1569-
def invert_yaxis(self, invert=True):
1570-
"Invert the y-axis if 'invert' is True."
1571-
self._invertedy = invert
1586+
def invert_yaxis(self):
1587+
"Invert the y-axis."
1588+
left, right = self.get_ylim()
1589+
self.set_ylim(right, left)
15721590

15731591
def yaxis_inverted(self):
15741592
'Returns True if the y-axis is inverted.'
1575-
return self._invertedy
1593+
left, right = self.get_ylim()
1594+
return right < left
1595+
1596+
def get_ybound(self):
1597+
"Returns the y-axis numerical bounds in the form of lowerBound < upperBound"
1598+
left, right = self.get_ylim()
1599+
if left < right:
1600+
return left, right
1601+
else:
1602+
return right, left
1603+
1604+
def set_ybound(self, lower=None, upper=None):
1605+
"""Set the lower and upper numerical bounds of the y-axis.
1606+
This method will honor axes inversion regardless of parameter order.
1607+
"""
1608+
if upper is None and iterable(lower):
1609+
lower,upper = lower
1610+
1611+
old_lower,old_upper = self.get_ybound()
1612+
1613+
if lower is None: lower = old_lower
1614+
if upper is None: upper = old_upper
1615+
1616+
if self.yaxis_inverted():
1617+
if lower < upper:
1618+
self.set_ylim(upper, lower)
1619+
else:
1620+
self.set_ylim(lower, upper)
1621+
else:
1622+
if lower < upper:
1623+
self.set_ylim(lower, upper)
1624+
else:
1625+
self.set_ylim(upper, lower)
15761626

15771627
def get_ylim(self):
15781628
"""Get the y-axis range [xmin, xmax]
@@ -1620,20 +1670,8 @@ def set_ylim(self, ymin=None, ymax=None, emit=True, **kwargs):
16201670
if ymin is None: ymin = old_ymin
16211671
if ymax is None: ymax = old_ymax
16221672

1623-
# provided for backwards compatability
1624-
if ( ymax < ymin ):
1625-
# swap the values so that ymin < ymax and set inverted flag
1626-
tmp = ymin
1627-
ymin = ymax
1628-
ymax = tmp
1629-
self.invert_yaxis( True )
1630-
1631-
if ( self._invertedy ):
1632-
ymax, ymin = mtransforms.nonsingular(ymax, ymin, increasing=False)
1633-
self.viewLim.intervaly = (ymax, ymin)
1634-
else:
1635-
ymin, ymax = mtransforms.nonsingular(ymin, ymax, increasing=False)
1636-
self.viewLim.intervaly = (ymin, ymax)
1673+
ymin, ymax = mtransforms.nonsingular(ymin, ymax, increasing=False)
1674+
self.viewLim.intervaly = (ymin, ymax)
16371675

16381676
if emit:
16391677
self.callbacks.process('ylim_changed', self)
@@ -2357,9 +2395,9 @@ def hlines(self, y, xmin, xmax, colors='k', linestyle='solid',
23572395
y = npy.asarray(y)
23582396

23592397
if len(xmin)==1:
2360-
xmin = xmin*ones(y.shape, y.dtype)
2398+
xmin = xmin*npy.ones(y.shape, y.dtype)
23612399
if len(xmax)==1:
2362-
xmax = xmax*ones(y.shape, y.dtype)
2400+
xmax = xmax*npy.ones(y.shape, y.dtype)
23632401

23642402
xmin = npy.asarray(xmin)
23652403
xmax = npy.asarray(xmax)
@@ -3199,9 +3237,9 @@ def make_iterable(x):
31993237
pass
32003238
elif align == 'center':
32013239
if orientation == 'vertical':
3202-
left = left - width/2.
3240+
left = [left[i] - width[i]/2. for i in range(len(left))]
32033241
elif orientation == 'horizontal':
3204-
bottom = bottom-height/2.
3242+
bottom = [bottom[i] - height[i]/2. for i in range(len(bottom))]
32053243

32063244
else:
32073245
raise ValueError, 'invalid alignment: %s' % align

lib/matplotlib/config/mpltraits.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def validate(self, object, name, value):
4646
def info(self):
4747
be = self.backends.keys()
4848
be.sort
49-
return "one of %s"% ', '.join('%s'%i for i in be)
49+
return "one of %s"% ', '.join(['%s'%i for i in be])
5050

5151

5252
class BoolHandler(T.TraitHandler):
@@ -73,7 +73,7 @@ def validate(self, object, name, value):
7373
return self.error(object, name, value)
7474

7575
def info(self):
76-
return "one of %s"% ', '.join('%s'%i for i in self.bools.keys())
76+
return "one of %s"% ', '.join(['%s'%i for i in self.bools.keys()])
7777

7878
flexible_true = T.Trait(True, BoolHandler())
7979
flexible_false = T.Trait(False, BoolHandler())

lib/matplotlib/contour.py

Lines changed: 19 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -397,12 +397,7 @@ def __init__(self, ax, *args, **kwargs):
397397
cmap = kwargs.get('cmap', None)
398398
self.colors = kwargs.get('colors', None)
399399
norm = kwargs.get('norm', None)
400-
self.clip_ends = kwargs.get('clip_ends', None) ########
401400
self.extend = kwargs.get('extend', 'neither')
402-
if self.clip_ends is not None:
403-
warnings.warn("'clip_ends' has been replaced by 'extend'")
404-
self.levels = self.levels[1:-1] # discard specified end levels
405-
self.extend = 'both' # regenerate end levels
406401
self.antialiased = kwargs.get('antialiased', True)
407402
self.nchunk = kwargs.get('nchunk', 0)
408403
self.locator = kwargs.get('locator', None)
@@ -436,18 +431,15 @@ def __init__(self, ax, *args, **kwargs):
436431
_mask = None
437432

438433
if self.filled:
439-
if self.linewidths is None:
440-
self.linewidths = 0.05 # Good default for Postscript.
441-
if cbook.iterable(self.linewidths):
442-
self.linewidths = self.linewidths[0]
434+
if self.linewidths is not None:
435+
warnings.warn('linewidths is ignored by contourf')
443436
C = _cntr.Cntr(x, y, z.filled(), _mask)
444437
lowers = self._levels[:-1]
445438
uppers = self._levels[1:]
446439
for level, level_upper in zip(lowers, uppers):
447440
nlist = C.trace(level, level_upper, points = 0,
448441
nchunk = self.nchunk)
449442
col = collections.PolyCollection(nlist,
450-
linewidths = (self.linewidths,),
451443
antialiaseds = (self.antialiased,),
452444
edgecolors= 'None')
453445
self.ax.add_collection(col)
@@ -500,16 +492,18 @@ def _autolev(self, z, N):
500492
one contour line, but two filled regions, and therefore
501493
three levels to provide boundaries for both regions.
502494
'''
503-
zmax = self.zmax
504-
zmin = self.zmin
505-
zmargin = (zmax - zmin) * 0.001 # so z < (zmax + zmargin)
506-
zmax = zmax + zmargin
507-
intv = transforms.Interval(transforms.Value(zmin), transforms.Value(zmax))
508495
if self.locator is None:
509496
self.locator = ticker.MaxNLocator(N+1)
510-
self.locator.set_view_interval(intv)
511-
self.locator.set_data_interval(intv)
512-
lev = self.locator()
497+
locator = self.locator
498+
zmax = self.zmax
499+
zmin = self.zmin
500+
locator.set_bounds(zmin, zmax)
501+
lev = locator()
502+
zmargin = (zmax - zmin) * 0.000001 # so z < (zmax + zmargin)
503+
if zmax >= lev[-1]:
504+
lev[-1] += zmargin
505+
if zmin <= lev[0]:
506+
lev[0] -= zmargin
513507
self._auto = True
514508
if self.filled:
515509
return lev
@@ -627,16 +621,16 @@ def _contour_args(self, *args):
627621
self._levels = npy.asarray(self._levels)
628622
self.vmin = npy.amin(self.levels) # alternative would be self.layers
629623
self.vmax = npy.amax(self.levels)
630-
if self.extend in ('both', 'min') or self.clip_ends:
624+
if self.extend in ('both', 'min'):
631625
self.vmin = 2 * self.levels[0] - self.levels[1]
632-
if self.extend in ('both', 'max') or self.clip_ends:
626+
if self.extend in ('both', 'max'):
633627
self.vmax = 2 * self.levels[-1] - self.levels[-2]
634628
self.layers = self._levels # contour: a line is a thin layer
635629
if self.filled:
636630
self.layers = 0.5 * (self._levels[:-1] + self._levels[1:])
637-
if self.extend in ('both', 'min') or self.clip_ends:
631+
if self.extend in ('both', 'min'):
638632
self.layers[0] = 0.5 * (self.vmin + self._levels[1])
639-
if self.extend in ('both', 'max') or self.clip_ends:
633+
if self.extend in ('both', 'max'):
640634
self.layers[-1] = 0.5 * (self.vmax + self._levels[-2])
641635

642636
return (x, y, z)
@@ -774,16 +768,14 @@ def set_alpha(self, alpha):
774768
contour levels if they are not given explicitly via the
775769
V argument.
776770
777-
***** New: *****
778771
* extend = 'neither', 'both', 'min', 'max'
779772
Unless this is 'neither' (default), contour levels are
780773
automatically added to one or both ends of the range so that
781774
all data are included. These added ranges are then
782775
mapped to the special colormap values which default to
783776
the ends of the colormap range, but can be set via
784777
Colormap.set_under() and Colormap.set_over() methods.
785-
To replace clip_ends=True and V = [-100, 2, 1, 0, 1, 2, 100],
786-
use extend='both' and V = [2, 1, 0, 1, 2].
778+
787779
****************
788780
789781
contour only:
@@ -799,29 +791,13 @@ def set_alpha(self, alpha):
799791
matplotlibrc is used
800792
801793
contourf only:
802-
***** Obsolete: ****
803-
* clip_ends = True
804-
If False, the limits for color scaling are set to the
805-
minimum and maximum contour levels.
806-
True (default) clips the scaling limits. Example:
807-
if the contour boundaries are V = [-100, 2, 1, 0, 1, 2, 100],
808-
then the scaling limits will be [-100, 100] if clip_ends
809-
is False, and [-3, 3] if clip_ends is True.
810-
* linewidths = None or a number; default of 0.05 works for
811-
Postscript; a value of about 0.5 seems better for Agg.
812-
* antialiased = True (default) or False; if False, there is
813-
no need to increase the linewidths for Agg, but True gives
814-
nicer color boundaries. If antialiased is True and linewidths
815-
is too small, then there may be light-colored lines at the
816-
color boundaries caused by the antialiasing.
794+
* antialiased = True (default) or False
817795
* nchunk = 0 (default) for no subdivision of the domain;
818796
specify a positive integer to divide the domain into
819797
subdomains of roughly nchunk by nchunk points. This may
820798
never actually be advantageous, so this option may be
821799
removed. Chunking introduces artifacts at the chunk
822-
boundaries unless antialiased = False, or linewidths is
823-
set to a large enough value for the particular renderer and
824-
resolution.
800+
boundaries unless antialiased = False
825801
"""
826802

827803

0 commit comments

Comments
 (0)