Revision: 3915 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3915&view=rev Author: mdboom Date: 2007-10-04 12:12:20 -0700 (Thu, 04 Oct 2007)
Log Message: ----------- Merged from trunk (a somewhat hairy manual merge this time). Fixed bug (on this branch only) where inverted axes were broken. Modified Paths: -------------- branches/transforms/lib/matplotlib/axes.py branches/transforms/lib/matplotlib/backends/backend_qt.py branches/transforms/lib/matplotlib/backends/backend_qt4.py branches/transforms/lib/matplotlib/backends/backend_qt4agg.py branches/transforms/lib/matplotlib/backends/backend_qtagg.py branches/transforms/lib/matplotlib/transforms.py Modified: branches/transforms/lib/matplotlib/axes.py =================================================================== --- branches/transforms/lib/matplotlib/axes.py 2007-10-04 18:57:27 UTC (rev 3914) +++ branches/transforms/lib/matplotlib/axes.py 2007-10-04 19:12:20 UTC (rev 3915) @@ -498,6 +498,9 @@ self.set_label(label) self.set_figure(fig) + self._invertedx = False + self._invertedy = False + # this call may differ for non-sep axes, eg polar self._init_axis() @@ -1422,10 +1425,25 @@ ### data limits, ticks, tick labels, and formatting + def invert_xaxis(self, invert=True): + "Invert the x-axis if 'invert' is True." + self._invertedx = invert + + def xaxis_inverted(self): + 'Returns True if the x-axis is inverted.' + return self._invertedx + def get_xlim(self): - 'Get the x axis range [xmin, xmax]' - return self.viewLim.intervalx + """Get the x-axis range [xmin, xmax] + NOTE: The returned values are always [xmin, xmax] such that + xmin < xmax; regardless of whether or not the axes are inverted. + """ + bound1, bound2 = self.viewLim.intervalx + if ( self._invertedx ): + return bound2, bound1 + else: + return bound1, bound2 def set_xlim(self, xmin=None, xmax=None, emit=True, **kwargs): """ @@ -1463,9 +1481,21 @@ if xmin is None: xmin = old_xmin if xmax is None: xmax = old_xmax - xmin, xmax = mtransforms.nonsingular(xmin, xmax, increasing=False) + # provided for backwards compatability + if ( xmax < xmin ): + # swap the values so that xmin < xmax and set inverted flag + tmp = xmin + xmin = xmax + xmax = tmp + self.invert_xaxis( True ) - self.viewLim.intervalx = (xmin, xmax) + if ( self._invertedx ): + xmax, xmin = mtransforms.nonsingular(xmax, xmin, increasing=False) + self.viewLim.intervalx = (xmax, xmin) + else: + xmin, xmax = mtransforms.nonsingular(xmin, xmax, increasing=False) + self.viewLim.intervalx = (xmin, xmax) + if emit: self.callbacks.process('xlim_changed', self) # Call all of the other x-axes that are shared with this one @@ -1534,10 +1564,26 @@ return self.xaxis.set_ticklabels(labels, fontdict, **kwargs) set_xticklabels.__doc__ = cbook.dedent(set_xticklabels.__doc__) % martist.kwdocd + def invert_yaxis(self, invert=True): + "Invert the y-axis if 'invert' is True." + self._invertedy = invert + + def yaxis_inverted(self): + 'Returns True if the y-axis is inverted.' + return self._invertedy + def get_ylim(self): - 'Get the y axis range [ymin, ymax]' - return self.viewLim.intervaly + """Get the y-axis range [xmin, xmax] + NOTE: The returned values are always [ymin, ymax] such that + ymin < ymax; regardless of whether or not the axes are inverted. + """ + bound1, bound2 = self.viewLim.intervaly + if ( self._invertedy ): + return bound2, bound1 + else: + return bound1, bound2 + def set_ylim(self, ymin=None, ymax=None, emit=True, **kwargs): """ set_ylim(self, *args, **kwargs): @@ -1572,8 +1618,21 @@ if ymin is None: ymin = old_ymin if ymax is None: ymax = old_ymax - ymin, ymax = mtransforms.nonsingular(ymin, ymax, increasing=False) - self.viewLim.intervaly = (ymin, ymax) + # provided for backwards compatability + if ( ymax < ymin ): + # swap the values so that ymin < ymax and set inverted flag + tmp = ymin + ymin = ymax + ymax = tmp + self.invert_yaxis( True ) + + if ( self._invertedy ): + ymax, ymin = mtransforms.nonsingular(ymax, ymin, increasing=False) + self.viewLim.intervaly = (ymax, ymin) + else: + ymin, ymax = mtransforms.nonsingular(ymin, ymax, increasing=False) + self.viewLim.intervaly = (ymin, ymax) + if emit: self.callbacks.process('ylim_changed', self) # Call all of the other y-axes that are shared with this one @@ -1582,7 +1641,6 @@ other.set_ylim(self.viewLim.ymin, self.viewLim.ymax, emit=False) self.figure.canvas.draw_idle() - return ymin, ymax def get_yscale(self): Modified: branches/transforms/lib/matplotlib/backends/backend_qt.py =================================================================== --- branches/transforms/lib/matplotlib/backends/backend_qt.py 2007-10-04 18:57:27 UTC (rev 3914) +++ branches/transforms/lib/matplotlib/backends/backend_qt.py 2007-10-04 19:12:20 UTC (rev 3915) @@ -136,10 +136,35 @@ def resizeEvent( self, event ): if DEBUG: print 'resize (%d x %d)' % (event.size().width(), event.size().height()) qt.QWidget.resizeEvent( self, event ) + w = event.size().width() + h = event.size().height() + if DEBUG: print "FigureCanvasQt.resizeEvent(", w, ",", h, ")" + dpival = self.figure.dpi.get() + winch = w/dpival + hinch = h/dpival + self.figure.set_size_inches( winch, hinch ) + self.draw() def resize( self, w, h ): + # Pass through to Qt to resize the widget. qt.QWidget.resize( self, w, h ) + # Resize the figure by converting pixels to inches. + pixelPerInch = self.figure.dpi.get() + wInch = w / pixelPerInch + hInch = h / pixelPerInch + self.figure.set_size_inches( wInch, hInch ) + + # Redraw everything. + self.draw() + + def sizeHint( self ): + w, h = self.get_width_height() + return qt.QSize( w, h ) + + def minumumSizeHint( self ): + return qt.QSize( 10, 10 ) + def _get_key( self, event ): if event.key() < 256: key = event.text().latin1() Modified: branches/transforms/lib/matplotlib/backends/backend_qt4.py =================================================================== --- branches/transforms/lib/matplotlib/backends/backend_qt4.py 2007-10-04 18:57:27 UTC (rev 3914) +++ branches/transforms/lib/matplotlib/backends/backend_qt4.py 2007-10-04 19:12:20 UTC (rev 3915) @@ -135,10 +135,35 @@ def resizeEvent( self, event ): if DEBUG: print 'resize (%d x %d)' % (event.size().width(), event.size().height()) QtGui.QWidget.resizeEvent( self, event ) + w = event.size().width() + h = event.size().height() + if DEBUG: print "FigureCanvasQtAgg.resizeEvent(", w, ",", h, ")" + dpival = self.figure.dpi.get() + winch = w/dpival + hinch = h/dpival + self.figure.set_size_inches( winch, hinch ) + self.draw() def resize( self, w, h ): + # Pass through to Qt to resize the widget. QtGui.QWidget.resize( self, w, h ) + # Resize the figure by converting pixels to inches. + pixelPerInch = self.figure.dpi.get() + wInch = w / pixelPerInch + hInch = h / pixelPerInch + self.figure.set_size_inches( wInch, hInch ) + + # Redraw everything. + self.draw() + + def sizeHint( self ): + w, h = self.get_width_height() + return QtCore.QSize( w, h ) + + def minumumSizeHint( self ): + return QtCore.QSize( 10, 10 ) + def _get_key( self, event ): if event.key() < 256: key = str(event.text()) Modified: branches/transforms/lib/matplotlib/backends/backend_qt4agg.py =================================================================== --- branches/transforms/lib/matplotlib/backends/backend_qt4agg.py 2007-10-04 18:57:27 UTC (rev 3914) +++ branches/transforms/lib/matplotlib/backends/backend_qt4agg.py 2007-10-04 19:12:20 UTC (rev 3915) @@ -65,14 +65,6 @@ def resizeEvent( self, e ): FigureCanvasQT.resizeEvent( self, e ) - w = e.size().width() - h = e.size().height() - if DEBUG: print "FigureCanvasQtAgg.resizeEvent(", w, ",", h, ")" - dpival = self.figure.dpi.get() - winch = w/dpival - hinch = h/dpival - self.figure.set_size_inches( winch, hinch ) - self.draw() def drawRectangle( self, rect ): self.rect = rect Modified: branches/transforms/lib/matplotlib/backends/backend_qtagg.py =================================================================== --- branches/transforms/lib/matplotlib/backends/backend_qtagg.py 2007-10-04 18:57:27 UTC (rev 3914) +++ branches/transforms/lib/matplotlib/backends/backend_qtagg.py 2007-10-04 19:12:20 UTC (rev 3915) @@ -64,14 +64,6 @@ def resizeEvent( self, e ): FigureCanvasQT.resizeEvent( self, e ) - w = e.size().width() - h = e.size().height() - if DEBUG: print "FigureCanvasQtAgg.resizeEvent(", w, ",", h, ")" - dpival = self.figure.dpi.get() - winch = w/dpival - hinch = h/dpival - self.figure.set_size_inches( winch, hinch ) - self.draw() def drawRectangle( self, rect ): self.rect = rect Modified: branches/transforms/lib/matplotlib/transforms.py =================================================================== --- branches/transforms/lib/matplotlib/transforms.py 2007-10-04 18:57:27 UTC (rev 3914) +++ branches/transforms/lib/matplotlib/transforms.py 2007-10-04 19:12:20 UTC (rev 3915) @@ -1951,10 +1951,12 @@ # MGDTODO: Optimize (perhaps in an extension) def interval_contains(interval, val): - return interval[0] <= val and interval[1] >= val + return ((interval[0] <= val and interval[1] >= val) or + (interval[1] <= val and interval[0] >= val)) def interval_contains_open(interval, val): - return interval[0] < val and interval[1] > val + return ((interval[0] < val and interval[1] > val) or + (interval[1] < val and interval[0] > val)) if __name__ == '__main__': import copy This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/ _______________________________________________ Matplotlib-checkins mailing list Matplotlib-checkins@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins