From: <jd...@us...> - 2008-06-27 15:26:05
|
Revision: 5688 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5688&view=rev Author: jdh2358 Date: 2008-06-27 08:25:50 -0700 (Fri, 27 Jun 2008) Log Message: ----------- more doc examples and cleanups Modified Paths: -------------- trunk/matplotlib/examples/pylab_examples/axhspan_demo.py trunk/matplotlib/examples/pylab_examples/barchart_demo.py trunk/matplotlib/examples/pylab_examples/contour_demo.py trunk/matplotlib/examples/pylab_examples/figimage_demo.py trunk/matplotlib/examples/pylab_examples/figlegend_demo.py trunk/matplotlib/examples/pylab_examples/log_demo.py trunk/matplotlib/lib/matplotlib/axes.py trunk/matplotlib/lib/matplotlib/contour.py trunk/matplotlib/lib/matplotlib/figure.py Modified: trunk/matplotlib/examples/pylab_examples/axhspan_demo.py =================================================================== --- trunk/matplotlib/examples/pylab_examples/axhspan_demo.py 2008-06-27 13:33:33 UTC (rev 5687) +++ trunk/matplotlib/examples/pylab_examples/axhspan_demo.py 2008-06-27 15:25:50 UTC (rev 5688) @@ -1,40 +1,32 @@ -#!/usr/bin/env python +import numpy as np +import matplotlib.pyplot as plt -from pylab import * -figure(1) -plot(10*rand(12), 'o') -xlim(0,15) -xticks([2, 4, 8, 12], ('John', 'Hunter', 'Was', 'Here')) +t = np.arange(-1,2, .01) +s = np.sin(2*np.pi*t) -ylim(-1,10) -yticks(range(8)) - -figure(2) -t = arange(-1,2, .01) -s = sin(2*pi*t) -plot(t,s) +plt.plot(t,s) # draw a thick red hline at y=0 that spans the xrange -l = axhline(linewidth=4, color='r') +l = plt.axhline(linewidth=4, color='r') # draw a default hline at y=1 that spans the xrange -l = axhline(y=1) +l = plt.axhline(y=1) # draw a default vline at x=1 that spans the xrange -l = axvline(x=1) +l = plt.axvline(x=1) # draw a thick blue vline at x=0 that spans the the upper quadrant of # the yrange -l = axvline(x=0, ymin=0.75, linewidth=4, color='b') +l = plt.axvline(x=0, ymin=0.75, linewidth=4, color='b') # draw a default hline at y=.5 that spans the the middle half of # the axes -l = axhline(y=.5, xmin=0.25, xmax=0.75) +l = plt.axhline(y=.5, xmin=0.25, xmax=0.75) -p = axhspan(0.25, 0.75, facecolor='0.5', alpha=0.5) +p = plt.axhspan(0.25, 0.75, facecolor='0.5', alpha=0.5) -p = axvspan(1.25, 1.55, facecolor='g', alpha=0.5) +p = plt.axvspan(1.25, 1.55, facecolor='g', alpha=0.5) -axis([-1,2,-1,2]) +plt.axis([-1,2,-1,2]) -show() +plt.show() Modified: trunk/matplotlib/examples/pylab_examples/barchart_demo.py =================================================================== --- trunk/matplotlib/examples/pylab_examples/barchart_demo.py 2008-06-27 13:33:33 UTC (rev 5687) +++ trunk/matplotlib/examples/pylab_examples/barchart_demo.py 2008-06-27 15:25:50 UTC (rev 5688) @@ -1,39 +1,38 @@ #!/usr/bin/env python -# a bar plot with errorbars -from numpy import arange -from matplotlib.pyplot import * +import numpy as np +import matplotlib.pyplot as plt N = 5 menMeans = (20, 35, 30, 35, 27) menStd = (2, 3, 4, 1, 2) -ind = arange(N) # the x locations for the groups +ind = np.arange(N) # the x locations for the groups width = 0.35 # the width of the bars -figure() -subplot(111) -rects1 = bar(ind, menMeans, width, color='r', yerr=menStd) +plt.subplot(111) +rects1 = plt.bar(ind, menMeans, width, color='r', yerr=menStd) + womenMeans = (25, 32, 34, 20, 25) womenStd = (3, 5, 2, 3, 3) -rects2 = bar(ind+width, womenMeans, width, color='y', yerr=womenStd) +rects2 = plt.bar(ind+width, womenMeans, width, color='y', yerr=womenStd) # add some -ylabel('Scores') -title('Scores by group and gender') -xticks(ind+width, ('G1', 'G2', 'G3', 'G4', 'G5') ) +plt.ylabel('Scores') +plt.title('Scores by group and gender') +plt.xticks(ind+width, ('G1', 'G2', 'G3', 'G4', 'G5') ) -legend( (rects1[0], rects2[0]), ('Men', 'Women') ) +plt.legend( (rects1[0], rects2[0]), ('Men', 'Women') ) def autolabel(rects): # attach some text labels for rect in rects: height = rect.get_height() - text(rect.get_x()+rect.get_width()/2., 1.05*height, '%d'%int(height), + plt.text(rect.get_x()+rect.get_width()/2., 1.05*height, '%d'%int(height), ha='center', va='bottom') autolabel(rects1) autolabel(rects2) #savefig('barchart_demo') -show() +plt.show() Modified: trunk/matplotlib/examples/pylab_examples/contour_demo.py =================================================================== --- trunk/matplotlib/examples/pylab_examples/contour_demo.py 2008-06-27 13:33:33 UTC (rev 5687) +++ trunk/matplotlib/examples/pylab_examples/contour_demo.py 2008-06-27 15:25:50 UTC (rev 5688) @@ -1,21 +1,25 @@ #!/usr/bin/env python -''' +""" Illustrate simple contour plotting, contours on an image with a colorbar for the contours, and labelled contours. See also contour_image.py. -''' -from pylab import * +""" +import matplotlib +import numpy as np +import matplotlib.cm as cm +import matplotlib.mlab as mlab +import matplotlib.pyplot as plt -rcParams['xtick.direction'] = 'out' -rcParams['ytick.direction'] = 'out' +matplotlib.rcParams['xtick.direction'] = 'out' +matplotlib.rcParams['ytick.direction'] = 'out' delta = 0.025 -x = arange(-3.0, 3.0, delta) -y = arange(-2.0, 2.0, delta) -X, Y = meshgrid(x, y) -Z1 = bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0) -Z2 = bivariate_normal(X, Y, 1.5, 0.5, 1, 1) +x = np.arange(-3.0, 3.0, delta) +y = np.arange(-2.0, 2.0, delta) +X, Y = np.meshgrid(x, y) +Z1 = mlab.bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0) +Z2 = mlab.bivariate_normal(X, Y, 1.5, 0.5, 1, 1) # difference of Gaussians Z = 10.0 * (Z2 - Z1) @@ -25,77 +29,77 @@ # inline argument to clabel will control whether the labels are draw # over the line segments of the contour, removing the lines beneath # the label -figure() -CS = contour(X, Y, Z) -clabel(CS, inline=1, fontsize=10) -title('Simplest default with labels') +plt.figure() +CS = plt.contour(X, Y, Z) +plt.clabel(CS, inline=1, fontsize=10) +plt.title('Simplest default with labels') # You can force all the contours to be the same color. -figure() -CS = contour(X, Y, Z, 6, - colors='k', # negative contours will be dashed by default - ) -clabel(CS, fontsize=9, inline=1) -title('Single color - negative contours dashed') +plt.figure() +CS = plt.contour(X, Y, Z, 6, + colors='k', # negative contours will be dashed by default + ) +plt.clabel(CS, fontsize=9, inline=1) +plt.title('Single color - negative contours dashed') # You can set negative contours to be solid instead of dashed: -rcParams['contour.negative_linestyle'] = 'solid' -figure() -CS = contour(X, Y, Z, 6, - colors='k', # negative contours will be dashed by default - ) -clabel(CS, fontsize=9, inline=1) -title('Single color - negative contours solid') +matplotlib.rcParams['contour.negative_linestyle'] = 'solid' +plt.figure() +CS = plt.contour(X, Y, Z, 6, + colors='k', # negative contours will be dashed by default + ) +plt.clabel(CS, fontsize=9, inline=1) +plt.title('Single color - negative contours solid') # And you can manually specify the colors of the contour -figure() -CS = contour(X, Y, Z, 6, - linewidths=arange(.5, 4, .5), - colors=('r', 'green', 'blue', (1,1,0), '#afeeee', '0.5') - ) -clabel(CS, fontsize=9, inline=1) -title('Crazy lines') +plt.figure() +CS = plt.contour(X, Y, Z, 6, + linewidths=np.arange(.5, 4, .5), + colors=('r', 'green', 'blue', (1,1,0), '#afeeee', '0.5') + ) +plt.clabel(CS, fontsize=9, inline=1) +plt.title('Crazy lines') # Or you can use a colormap to specify the colors; the default # colormap will be used for the contour lines -figure() -im = imshow(Z, interpolation='bilinear', origin='lower', - cmap=cm.gray, extent=(-3,3,-2,2)) -levels = arange(-1.2, 1.6, 0.2) -CS = contour(Z, levels, - origin='lower', - linewidths=2, - extent=(-3,3,-2,2)) +plt.figure() +im = plt.imshow(Z, interpolation='bilinear', origin='lower', + cmap=cm.gray, extent=(-3,3,-2,2)) +levels = np.arange(-1.2, 1.6, 0.2) +CS = plt.contour(Z, levels, + origin='lower', + linewidths=2, + extent=(-3,3,-2,2)) #Thicken the zero contour. zc = CS.collections[6] -setp(zc, linewidth=4) +plt.setp(zc, linewidth=4) -clabel(CS, levels[1::2], # label every second level - inline=1, - fmt='%1.1f', - fontsize=14) +plt.clabel(CS, levels[1::2], # label every second level + inline=1, + fmt='%1.1f', + fontsize=14) # make a colorbar for the contour lines -CB = colorbar(CS, shrink=0.8, extend='both') +CB = plt.colorbar(CS, shrink=0.8, extend='both') -title('Lines with colorbar') -hot() # Now change the colormap for the contour lines and colorbar -flag() +plt.title('Lines with colorbar') +#plt.hot() # Now change the colormap for the contour lines and colorbar +plt.flag() # We can still add a colorbar for the image, too. -CBI = colorbar(im, orientation='horizontal', shrink=0.8) +CBI = plt.colorbar(im, orientation='horizontal', shrink=0.8) # This makes the original colorbar look a bit out of place, # so let's improve its position. -l,b,w,h = gca().get_position().bounds +l,b,w,h = plt.gca().get_position().bounds ll,bb,ww,hh = CB.ax.get_position().bounds CB.ax.set_position([ll, b+0.1*h, ww, h*0.8]) #savefig('contour_demo') -show() +plt.show() Modified: trunk/matplotlib/examples/pylab_examples/figimage_demo.py =================================================================== --- trunk/matplotlib/examples/pylab_examples/figimage_demo.py 2008-06-27 13:33:33 UTC (rev 5687) +++ trunk/matplotlib/examples/pylab_examples/figimage_demo.py 2008-06-27 15:25:50 UTC (rev 5688) @@ -1,21 +1,21 @@ -#!/usr/bin/env python """ See pcolor_demo2 for a much faster way of generating pcolor plots """ -from __future__ import division -from pylab import * -rc('axes', hold=True) -rc('image', origin='upper') -figure(1, frameon=False) -Z = arange(10000.0); Z.shape = 100,100 -Z[:,50:] = 1 -jet() # sets the default -im1 = figimage(Z, xo=50, yo=0) -im2 = figimage(Z, xo=100, yo=100, alpha=.8) -#gray() # overrides current and sets default -#savefig('figimage_demo') +import numpy as np +import matplotlib +import matplotlib.cm as cm +import matplotlib.pyplot as plt -show() +fig = plt.figure(frameon=False) +Z = np.arange(10000.0) +Z.shape = 100,100 +Z[:,50:] = 1. +im1 = plt.figimage(Z, xo=50, yo=0, cmap=cm.jet) +im2 = plt.figimage(Z, xo=100, yo=100, alpha=.8, cmap=cm.jet) +plt.show() + + + Modified: trunk/matplotlib/examples/pylab_examples/figlegend_demo.py =================================================================== --- trunk/matplotlib/examples/pylab_examples/figlegend_demo.py 2008-06-27 13:33:33 UTC (rev 5687) +++ trunk/matplotlib/examples/pylab_examples/figlegend_demo.py 2008-06-27 15:25:50 UTC (rev 5688) @@ -1,18 +1,19 @@ -#!/usr/bin/env python +import numpy as np +import matplotlib.pyplot as plt -from pylab import * -ax1 = axes([0.1, 0.1, 0.4, 0.7]) -ax2 = axes([0.55, 0.1, 0.4, 0.7]) +fig = plt.figure() +ax1 = fig.add_axes([0.1, 0.1, 0.4, 0.7]) +ax2 = fig.add_axes([0.55, 0.1, 0.4, 0.7]) -x = arange(0.0, 2.0, 0.02) -y1 = sin(2*pi*x) -y2 = exp(-x) +x = np.arange(0.0, 2.0, 0.02) +y1 = np.sin(2*np.pi*x) +y2 = np.exp(-x) l1, l2 = ax1.plot(x, y1, 'rs-', x, y2, 'go') -y3 = sin(4*pi*x) -y4 = exp(-2*x) +y3 = np.sin(4*np.pi*x) +y4 = np.exp(-2*x) l3, l4 = ax2.plot(x, y3, 'yd-', x, y3, 'k^') -figlegend((l1, l2), ('Line 1', 'Line 2'), 'upper left') -figlegend((l3, l4), ('Line 3', 'Line 4'), 'upper right') -show() +fig.legend((l1, l2), ('Line 1', 'Line 2'), 'upper left') +fig.legend((l3, l4), ('Line 3', 'Line 4'), 'upper right') +plt.show() Modified: trunk/matplotlib/examples/pylab_examples/log_demo.py =================================================================== --- trunk/matplotlib/examples/pylab_examples/log_demo.py 2008-06-27 13:33:33 UTC (rev 5687) +++ trunk/matplotlib/examples/pylab_examples/log_demo.py 2008-06-27 15:25:50 UTC (rev 5688) @@ -1,26 +1,25 @@ -#!/usr/bin/env python -from pylab import * +import numpy as np +import matplotlib.pyplot as plt -dt = 0.01 -t = arange(dt, 20.0, dt) +plt.subplots_adjust(hspace=0.4) +t = np.arange(0.01, 20.0, 0.01) -subplot(311) -semilogy(t, exp(-t/5.0)) -ylabel('semilogy') -grid(True) +# log y axis +plt.subplot(311) +plt.semilogy(t, np.exp(-t/5.0)) +plt.ylabel('semilogy') +plt.grid(True) -subplot(312) -semilogx(t, sin(2*pi*t)) -ylabel('semilogx') +# log x axis +plt.subplot(312) +plt.semilogx(t, np.sin(2*np.pi*t)) +plt.ylabel('semilogx') +plt.grid(True) +# log x and y axis +plt.subplot(313) +plt.loglog(t, 20*np.exp(-t/10.0), basex=4) +plt.grid(True) +plt.ylabel('loglog base 4 on x') - -grid(True) -gca().xaxis.grid(True, which='minor') # minor grid on too - -subplot(313) -loglog(t, 20*exp(-t/10.0), basex=4) -grid(True) -ylabel('loglog base 4 on x') -savefig('log_demo') -show() +plt.show() Modified: trunk/matplotlib/lib/matplotlib/axes.py =================================================================== --- trunk/matplotlib/lib/matplotlib/axes.py 2008-06-27 13:33:33 UTC (rev 5687) +++ trunk/matplotlib/lib/matplotlib/axes.py 2008-06-27 15:25:50 UTC (rev 5688) @@ -2697,6 +2697,8 @@ Valid kwargs are :class:`~matplotlib.lines.Line2D` properties: %(Line2D)s + + See :meth:`axhspan` for example plot and source code """ ymin, ymax = self.get_ylim() @@ -2747,6 +2749,8 @@ Valid kwargs are :class:`~matplotlib.lines.Line2D` properties: %(Line2D)s + + See :meth:`axhspan` for example plot and source code """ xmin, xmax = self.get_xlim() @@ -2793,6 +2797,11 @@ Valid kwargs are :class:`~matplotlib.patches.Polygon` properties: %(Polygon)s + + **Example:** + + .. plot:: ../mpl_examples/pylab_examples/axhspan_demo.py + """ # convert y axis units trans = mtransforms.blended_transform_factory( @@ -2836,6 +2845,8 @@ properties: %(Polygon)s + + See :meth:`axhspan` for example plot and source code """ # convert x axis units trans = mtransforms.blended_transform_factory( @@ -3214,6 +3225,11 @@ :class:`~matplotlib.lines.Line2D` properties: %(Line2D)s + + **Example:** + + .. plot:: ../mpl_examples/pylab_examples/log_demo.py + """ if not self._hold: self.cla() @@ -3262,6 +3278,8 @@ :class:`~matplotlib.lines.Line2D` properties: %(Line2D)s + + See :meth:`loglog` for example code and figure """ if not self._hold: self.cla() d = {'basex': kwargs.pop( 'basex', 10), @@ -3303,6 +3321,8 @@ :class:`~matplotlib.lines.Line2D` properties: %(Line2D)s + + See :meth:`loglog` for example code and figure """ if not self._hold: self.cla() d = {'basey': kwargs.pop('basey', 10), @@ -3371,6 +3391,8 @@ :func:`~matplotlib.pyplot.xcorr` above, and :func:`~matplotlib.pyplot.acorr` below. + **Example:** + .. plot:: ../mpl_examples/pylab_examples/xcorr_demo.py """ return self.xcorr(x, x, **kwargs) @@ -3426,6 +3448,8 @@ :func:`~matplotlib.pyplot.xcorr` above, and :func:`~matplotlib.pyplot.acorr` below. + **Example:** + .. plot:: ../mpl_examples/pylab_examples/xcorr_demo.py """ @@ -3565,6 +3589,10 @@ *axespad*: [ None | scalar ] The border between the axes and legend edge. If *None*, use rc settings. + + **Example:** + + .. plot:: legend_demo.py """ def get_handles(): @@ -3724,10 +3752,8 @@ %(Rectangle)s - **Example:** + **Example:** A stacked bar chart. - A stacked bar chart. - .. plot:: ../mpl_examples/pylab_examples/bar_stacked.py """ if not self._hold: self.cla() @@ -4295,6 +4321,11 @@ the third element is a list of :class:`~matplotlib.collections.LineCollection` instances for the horizontal and vertical error ranges. + + **Example:** + + .. plot:: errorbar_demo.py + """ self._process_unit_info(xdata=x, ydata=y, kwargs=kwargs) @@ -4496,6 +4527,9 @@ Returns a list of the :class:`matplotlib.lines.Line2D` instances added. + **Example:** + + .. plot:: boxplot_demo.py """ if not self._hold: self.cla() holdStatus = self._hold Modified: trunk/matplotlib/lib/matplotlib/contour.py =================================================================== --- trunk/matplotlib/lib/matplotlib/contour.py 2008-06-27 13:33:33 UTC (rev 5687) +++ trunk/matplotlib/lib/matplotlib/contour.py 2008-06-27 15:25:50 UTC (rev 5688) @@ -69,6 +69,7 @@ *fmt*: a format string for the label. Default is '%1.3f' + """ fontsize = kwargs.get('fontsize', None) inline = kwargs.get('inline', 1) @@ -892,4 +893,5 @@ be removed. Chunking introduces artifacts at the chunk boundaries unless *antialiased* is *False*. + .. plot:: contour_demo.py """ Modified: trunk/matplotlib/lib/matplotlib/figure.py =================================================================== --- trunk/matplotlib/lib/matplotlib/figure.py 2008-06-27 13:33:33 UTC (rev 5687) +++ trunk/matplotlib/lib/matplotlib/figure.py 2008-06-27 15:25:50 UTC (rev 5688) @@ -468,6 +468,9 @@ :class:`~matplotlib.axes.Axes` with size [0,1,0,1]. An :class:`matplotlib.image.FigureImage` instance is returned. + + .. plot:: ../mpl_examples/pylab_examples/figimage_demo.py + """ if not self._hold: self.clf() @@ -912,6 +915,7 @@ *axespad* the border between the axes and legend edge + .. plot:: ../mpl_examples/pylab_examples/figlegend_demo.py """ handles = flatten(handles) l = Legend(self, handles, labels, *args, **kwargs) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jd...@us...> - 2008-06-27 15:55:31
|
Revision: 5689 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5689&view=rev Author: jdh2358 Date: 2008-06-27 08:33:17 -0700 (Fri, 27 Jun 2008) Log Message: ----------- fixed errorbar demo Modified Paths: -------------- trunk/matplotlib/doc/sphinxext/plot_directive.py trunk/matplotlib/lib/matplotlib/contour.py Modified: trunk/matplotlib/doc/sphinxext/plot_directive.py =================================================================== --- trunk/matplotlib/doc/sphinxext/plot_directive.py 2008-06-27 15:25:50 UTC (rev 5688) +++ trunk/matplotlib/doc/sphinxext/plot_directive.py 2008-06-27 15:33:17 UTC (rev 5689) @@ -43,7 +43,7 @@ template = """ .. htmlonly:: - [`py <../%(srcdir)s/%(basename)s.py>`__, + [`source code <../%(srcdir)s/%(basename)s.py>`__, `png <../%(srcdir)s/%(basename)s.hires.png>`__, `pdf <../%(srcdir)s/%(basename)s.pdf>`__] Modified: trunk/matplotlib/lib/matplotlib/contour.py =================================================================== --- trunk/matplotlib/lib/matplotlib/contour.py 2008-06-27 15:25:50 UTC (rev 5688) +++ trunk/matplotlib/lib/matplotlib/contour.py 2008-06-27 15:33:17 UTC (rev 5689) @@ -893,5 +893,7 @@ be removed. Chunking introduces artifacts at the chunk boundaries unless *antialiased* is *False*. + **Example:** + .. plot:: contour_demo.py """ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <md...@us...> - 2008-06-27 18:53:16
|
Revision: 5694 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5694&view=rev Author: mdboom Date: 2008-06-27 11:53:11 -0700 (Fri, 27 Jun 2008) Log Message: ----------- Fix dashed text bug where text was at the wrong end of the dash (Thanks Andrea Gavana) Modified Paths: -------------- trunk/matplotlib/CHANGELOG trunk/matplotlib/lib/matplotlib/text.py Modified: trunk/matplotlib/CHANGELOG =================================================================== --- trunk/matplotlib/CHANGELOG 2008-06-27 15:42:44 UTC (rev 5693) +++ trunk/matplotlib/CHANGELOG 2008-06-27 18:53:11 UTC (rev 5694) @@ -1,3 +1,6 @@ +2008-06-27 Fix dashed text bug where text was at the wrong end of the + dash - MGD + 2008-06-26 Fix mathtext bug for expressions like $x_{\leftarrow}$ - MGD 2008-06-26 Fix direction of horizontal/vertical hatches - MGD Modified: trunk/matplotlib/lib/matplotlib/text.py =================================================================== --- trunk/matplotlib/lib/matplotlib/text.py 2008-06-27 15:42:44 UTC (rev 5693) +++ trunk/matplotlib/lib/matplotlib/text.py 2008-06-27 18:53:11 UTC (rev 5694) @@ -745,8 +745,8 @@ def get_position(self): "Return x, y as tuple" - x = float(self.convert_xunits(self._dashx)) - y = float(self.convert_yunits(self._dashy)) + x = float(self.convert_xunits(self._x)) + y = float(self.convert_yunits(self._y)) return x, y def get_prop_tup(self): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mme...@us...> - 2008-06-28 01:11:00
|
Revision: 5696 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5696&view=rev Author: mmetz_bn Date: 2008-06-27 18:10:58 -0700 (Fri, 27 Jun 2008) Log Message: ----------- Fixed tick positioning bug Modified Paths: -------------- trunk/matplotlib/CHANGELOG trunk/matplotlib/lib/matplotlib/text.py Modified: trunk/matplotlib/CHANGELOG =================================================================== --- trunk/matplotlib/CHANGELOG 2008-06-27 18:54:51 UTC (rev 5695) +++ trunk/matplotlib/CHANGELOG 2008-06-28 01:10:58 UTC (rev 5696) @@ -1,3 +1,5 @@ +2008-06-27 Fixed tick positioning bug - MM + 2008-06-27 Fix dashed text bug where text was at the wrong end of the dash - MGD Modified: trunk/matplotlib/lib/matplotlib/text.py =================================================================== --- trunk/matplotlib/lib/matplotlib/text.py 2008-06-27 18:54:51 UTC (rev 5695) +++ trunk/matplotlib/lib/matplotlib/text.py 2008-06-28 01:10:58 UTC (rev 5696) @@ -939,7 +939,8 @@ ACCEPTS: float """ - self._dashx = float(x) + self._x = float(x) + self._dashx = self._x def set_y(self, y): """ @@ -947,7 +948,8 @@ ACCEPTS: float """ - self._dashy = float(y) + self._y = float(y) + self._dashy = self._y def set_transform(self, t): """ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ds...@us...> - 2008-06-30 13:21:30
|
Revision: 5699 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5699&view=rev Author: dsdale Date: 2008-06-30 06:21:19 -0700 (Mon, 30 Jun 2008) Log Message: ----------- removed Qt4's NavigationToolbar2.destroy method Modified Paths: -------------- trunk/matplotlib/CHANGELOG trunk/matplotlib/lib/matplotlib/backends/backend_qt4.py Modified: trunk/matplotlib/CHANGELOG =================================================================== --- trunk/matplotlib/CHANGELOG 2008-06-30 12:13:55 UTC (rev 5698) +++ trunk/matplotlib/CHANGELOG 2008-06-30 13:21:19 UTC (rev 5699) @@ -1,3 +1,7 @@ +2008-06-30 Removed Qt4 NavigationToolbar2.destroy -- it appears to + have been unnecessary and caused a bug reported by P. + Raybaut - DSD + 2008-06-27 Fixed tick positioning bug - MM 2008-06-27 Fix dashed text bug where text was at the wrong end of the Modified: trunk/matplotlib/lib/matplotlib/backends/backend_qt4.py =================================================================== --- trunk/matplotlib/lib/matplotlib/backends/backend_qt4.py 2008-06-30 12:13:55 UTC (rev 5698) +++ trunk/matplotlib/lib/matplotlib/backends/backend_qt4.py 2008-06-30 13:21:19 UTC (rev 5699) @@ -311,13 +311,6 @@ # reference holder for subplots_adjust window self.adj_window = None - def destroy( self ): - for text, tooltip_text, image_file, callback in self.toolitems: - if text is not None: - QtCore.QObject.disconnect( self.buttons[ text ], - QtCore.SIGNAL( 'clicked()' ), - getattr( self, callback ) ) - def dynamic_update( self ): self.canvas.draw() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ds...@us...> - 2008-06-30 23:14:47
|
Revision: 5701 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5701&view=rev Author: dsdale Date: 2008-06-30 16:14:42 -0700 (Mon, 30 Jun 2008) Log Message: ----------- another attempt to fix TextWithDash Modified Paths: -------------- trunk/matplotlib/CHANGELOG trunk/matplotlib/lib/matplotlib/text.py Modified: trunk/matplotlib/CHANGELOG =================================================================== --- trunk/matplotlib/CHANGELOG 2008-06-30 13:24:13 UTC (rev 5700) +++ trunk/matplotlib/CHANGELOG 2008-06-30 23:14:42 UTC (rev 5701) @@ -1,3 +1,5 @@ +2008-06-30 Another attempt to fix TextWithDash - DSD + 2008-06-30 Removed Qt4 NavigationToolbar2.destroy -- it appears to have been unnecessary and caused a bug reported by P. Raybaut - DSD Modified: trunk/matplotlib/lib/matplotlib/text.py =================================================================== --- trunk/matplotlib/lib/matplotlib/text.py 2008-06-30 13:24:13 UTC (rev 5700) +++ trunk/matplotlib/lib/matplotlib/text.py 2008-06-30 23:14:42 UTC (rev 5701) @@ -298,7 +298,12 @@ bbox, info = self._get_layout(renderer) trans = self.get_transform() - posx, posy = self.get_position() + + # don't use self.get_position here, which refers to text position + # in Text, and dash position in TextWithDash: + posx = float(self.convert_xunits(self._x)) + posy = float(self.convert_yunits(self._y)) + posx, posy = trans.transform_point((posx, posy)) canvasw, canvash = renderer.get_canvas_width_height() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jd...@us...> - 2008-07-02 11:08:51
|
Revision: 5705 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5705&view=rev Author: jdh2358 Date: 2008-07-02 04:08:22 -0700 (Wed, 02 Jul 2008) Log Message: ----------- cleaned legend demo example Modified Paths: -------------- trunk/matplotlib/examples/pylab_examples/hexbin_demo.py trunk/matplotlib/examples/pylab_examples/legend_demo.py trunk/matplotlib/lib/matplotlib/axes.py Added Paths: ----------- trunk/matplotlib/examples/api/legend_demo.py Added: trunk/matplotlib/examples/api/legend_demo.py =================================================================== --- trunk/matplotlib/examples/api/legend_demo.py (rev 0) +++ trunk/matplotlib/examples/api/legend_demo.py 2008-07-02 11:08:22 UTC (rev 5705) @@ -0,0 +1,41 @@ +import numpy as np +import matplotlib.pyplot as plt + +a = np.arange(0,3,.02) +b = np.arange(0,3,.02) +c = np.exp(a) +d = c[::-1] + +fig = plt.figure() +ax = fig.add_subplot(111) +ax.plot(a,c,'k--',a,d,'k:',a,c+d,'k') +leg = ax.legend(('Model length', 'Data length', 'Total message length'), + 'upper center', shadow=True) +ax.set_ylim([-1,20]) +ax.grid(False) +ax.set_xlabel('Model complexity --->') +ax.set_ylabel('Message length --->') +ax.set_title('Minimum Message Length') + +ax.set_yticklabels([]) +ax.set_xticklabels([]) + +# set some legend properties. All the code below is optional. The +# defaults are usually sensible but if you need more control, this +# shows you how + +# the matplotlib.patches.Rectangle instance surrounding the legend +frame = leg.get_frame() +frame.set_facecolor('0.80') # set the frame face color to light gray + +# matplotlib.text.Text instances +for t in leg.get_texts(): + t.set_fontsize('small') # the legend text fontsize + +# matplotlib.lines.Line2D instances +for l in leg.get_lines(): + l.set_linewidth(1.5) # the legend line width +plt.show() + + + Modified: trunk/matplotlib/examples/pylab_examples/hexbin_demo.py =================================================================== --- trunk/matplotlib/examples/pylab_examples/hexbin_demo.py 2008-07-01 12:01:38 UTC (rev 5704) +++ trunk/matplotlib/examples/pylab_examples/hexbin_demo.py 2008-07-02 11:08:22 UTC (rev 5705) @@ -6,7 +6,9 @@ """ import numpy as np +import matplotlib.cm as cm import matplotlib.pyplot as plt + n = 100000 x = np.random.standard_normal(n) y = 2.0 + 3.0 * x + 4.0 * np.random.standard_normal(n) @@ -17,14 +19,14 @@ plt.subplots_adjust(hspace=0.5) plt.subplot(121) -plt.hexbin(x,y) +plt.hexbin(x,y, cmap=cm.jet) plt.axis([xmin, xmax, ymin, ymax]) plt.title("Hexagon binning") cb = plt.colorbar() cb.set_label('counts') plt.subplot(122) -plt.hexbin(x,y,bins='log') +plt.hexbin(x,y,bins='log', cmap=cm.jet) plt.axis([xmin, xmax, ymin, ymax]) plt.title("With a log color scale") cb = plt.colorbar() Modified: trunk/matplotlib/examples/pylab_examples/legend_demo.py =================================================================== --- trunk/matplotlib/examples/pylab_examples/legend_demo.py 2008-07-01 12:01:38 UTC (rev 5704) +++ trunk/matplotlib/examples/pylab_examples/legend_demo.py 2008-07-02 11:08:22 UTC (rev 5705) @@ -4,32 +4,31 @@ #See http://matplotlib.sf.net/examples/legend_demo2.py for an example #controlling which lines the legend uses and the order +import numpy as np +import matplotlib.pyplot as plt -from pylab import * +a = np.arange(0,3,.02) +b = np.arange(0,3,.02) +c = np.exp(a) +d = c[::-1] -a = arange(0,3,.02) -b = arange(0,3,.02) -c=exp(a) -d=c.tolist() -d.reverse() -d = array(d) +ax = plt.subplot(111) +plt.plot(a,c,'k--',a,d,'k:',a,c+d,'k') +plt.legend(('Model length', 'Data length', 'Total message length'), + 'upper center', shadow=True) +plt.ylim([-1,20]) +plt.grid(False) +plt.xlabel('Model complexity --->') +plt.ylabel('Message length --->') +plt.title('Minimum Message Length') -ax = subplot(111) -plot(a,c,'k--',a,d,'k:',a,c+d,'k') -legend(('Model length', 'Data length', 'Total message length'), - 'upper center', shadow=True) -ax.set_ylim([-1,20]) -ax.grid(0) -xlabel('Model complexity --->') -ylabel('Message length --->') -title('Minimum Message Length') -setp(gca(), 'yticklabels', []) -setp(gca(), 'xticklabels', []) +plt.setp(plt.gca(), 'yticklabels', []) +plt.setp(plt.gca(), 'xticklabels', []) # set some legend properties. All the code below is optional. The # defaults are usually sensible but if you need more control, this # shows you how -leg = gca().get_legend() +leg = plt.gca().get_legend() ltext = leg.get_texts() # all the text.Text instance in the legend llines = leg.get_lines() # all the lines.Line2D instance in the legend frame = leg.get_frame() # the patch.Rectangle instance surrounding the legend @@ -37,11 +36,11 @@ # see text.Text, lines.Line2D, and patches.Rectangle for more info on # the settable properties of lines, text, and rectangles frame.set_facecolor('0.80') # set the frame face color to light gray -setp(ltext, fontsize='small') # the legend text fontsize -setp(llines, linewidth=1.5) # the legend linewidth +plt.setp(ltext, fontsize='small') # the legend text fontsize +plt.setp(llines, linewidth=1.5) # the legend linewidth #leg.draw_frame(False) # don't draw the legend frame -#savefig('legend_demo') -show() +#plt.savefig('legend_demo') +plt.show() Modified: trunk/matplotlib/lib/matplotlib/axes.py =================================================================== --- trunk/matplotlib/lib/matplotlib/axes.py 2008-07-01 12:01:38 UTC (rev 5704) +++ trunk/matplotlib/lib/matplotlib/axes.py 2008-07-02 11:08:22 UTC (rev 5705) @@ -3592,7 +3592,7 @@ **Example:** - .. plot:: legend_demo.py + .. plot:: ../mpl_examples/api/legend_demo.py """ def get_handles(): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jd...@us...> - 2008-07-03 13:22:14
|
Revision: 5707 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5707&view=rev Author: jdh2358 Date: 2008-07-03 06:21:54 -0700 (Thu, 03 Jul 2008) Log Message: ----------- axes was not calling artist set_axes method in set artist props Modified Paths: -------------- trunk/matplotlib/examples/widgets/menu.py trunk/matplotlib/lib/matplotlib/axes.py trunk/matplotlib/lib/matplotlib/pyplot.py trunk/matplotlib/src/_backend_agg.cpp trunk/matplotlib/src/_backend_agg.h trunk/matplotlib/unit/memleak_hawaii3.py Modified: trunk/matplotlib/examples/widgets/menu.py =================================================================== --- trunk/matplotlib/examples/widgets/menu.py 2008-07-02 15:36:38 UTC (rev 5706) +++ trunk/matplotlib/examples/widgets/menu.py 2008-07-03 13:21:54 UTC (rev 5707) @@ -1,45 +1,76 @@ import numpy as np import matplotlib +import matplotlib.colors as colors import matplotlib.patches as patches import matplotlib.mathtext as mathtext import matplotlib.pyplot as plt import matplotlib.artist as artist import matplotlib.image as image -matplotlib.rc('image', origin='upper') +class ItemProperties: + def __init__(self, fontsize=14, labelcolor='black', bgcolor='yellow', alpha=1.0): + self.fontsize = fontsize + self.labelcolor = labelcolor + self.bgcolor = bgcolor + self.alpha = alpha + + self.labelcolor_rgb = colors.colorConverter.to_rgb(labelcolor) + self.bgcolor_rgb = colors.colorConverter.to_rgb(bgcolor) + class MenuItem(artist.Artist): parser = mathtext.MathTextParser("Bitmap") padx = 5 pady =5 - def __init__(self, fig, labelstr): + def __init__(self, fig, labelstr, props=None, hoverprops=None, on_select=None): artist.Artist.__init__(self) + self.set_figure(fig) + self.labelstr = labelstr + if props is None: + props = ItemProperties() - x, self.depth = self.parser.to_rgba( - labelstr, color='black', fontsize=14, dpi=100) - xHover, depth = self.parser.to_rgba( - labelstr, color='white', fontsize=14, dpi=100) + if hoverprops is None: + hoverprops = ItemProperties() + self.props = props + self.hoverprops = hoverprops + + self.on_select = on_select + + x, self.depth = self.parser.to_mask( + labelstr, fontsize=props.fontsize, dpi=fig.dpi) + + if props.fontsize!=hoverprops.fontsize: + raise NotImplementedError('support for different font sizes not implemented') + + self.labelwidth = x.shape[1] self.labelheight = x.shape[0] - print 'h', self.labelheight - self.label = image.FigureImage(fig) - self.label.set_array(x.astype(float)/255.) - self.labelHover = image.FigureImage(fig) - self.labelHover.set_array(xHover.astype(float)/255.) + self.labelArray = np.zeros((x.shape[0], x.shape[1], 4)) + self.labelArray[:,:,-1] = x/255. + self.label = image.FigureImage(fig, origin='upper') + self.label.set_array(self.labelArray) - # we'll update these later - self.rect = patches.Rectangle((0,0), 1,1, facecolor='yellow', alpha=0.2) - self.rectHover = patches.Rectangle((0,0), 1,1, facecolor='blue', alpha=0.2) + self.rect = patches.Rectangle((0,0), 1,1) + self.set_hover_props(False) + fig.canvas.mpl_connect('button_release_event', self.check_select) + def check_select(self, event): + over, junk = self.rect.contains(event) + if not over: + return + + if self.on_select is not None: + self.on_select(self) + def set_extent(self, x, y, w, h): print x, y, w, h self.rect.set_x(x) @@ -47,65 +78,64 @@ self.rect.set_width(w) self.rect.set_height(h) - self.rectHover.set_x(x) - self.rectHover.set_y(y) - self.rectHover.set_width(w) - self.rectHover.set_height(h) - self.label.ox = x+self.padx self.label.oy = y-self.depth+self.pady/2. self.rect._update_patch_transform() - self.rectHover._update_patch_transform() - self.labelHover.ox = x+self.padx - self.labelHover.oy = y-self.depth+self.pady/2. self.hover = False - self.activeRect = self.rect - self.activeLabel = self.label - def draw(self, renderer): - self.activeRect.draw(renderer) - self.activeLabel.draw(renderer) + self.rect.draw(renderer) + self.label.draw(renderer) + def set_hover_props(self, b): + if b: + props = self.hoverprops + else: + props = self.props + + r, g, b = props.labelcolor_rgb + self.labelArray[:,:,0] = r + self.labelArray[:,:,1] = g + self.labelArray[:,:,2] = b + self.label.set_array(self.labelArray) + self.rect.set(facecolor=props.bgcolor, alpha=props.alpha) + def set_hover(self, event): 'check the hover status of event and return true if status is changed' b,junk = self.rect.contains(event) - if b: - self.activeRect = self.rectHover - self.activeLabel = self.labelHover - else: - self.activeRect = self.rect - self.activeLabel = self.label - h = self.hover + changed = (b != self.hover) + + if changed: + self.set_hover_props(b) + + self.hover = b - return b!=h + return changed class Menu: - def __init__(self, fig, labels): + def __init__(self, fig, menuitems): self.figure = fig fig.suppressComposite = True - menuitems = [] - self.numitems = len(labels) - for label in labels: - menuitems.append(MenuItem(fig, label)) self.menuitems = menuitems + self.numitems = len(menuitems) - maxw = max([item.labelwidth for item in menuitems]) maxh = max([item.labelheight for item in menuitems]) totalh = self.numitems*maxh + (self.numitems+1)*2*MenuItem.pady + x0 = 100 y0 = 400 width = maxw + 2*MenuItem.padx height = maxh+MenuItem.pady + for item in menuitems: left = x0 bottom = y0-maxh-MenuItem.pady @@ -122,17 +152,27 @@ def on_move(self, event): draw = False for item in self.menuitems: - b = item.set_hover(event) - draw = b + draw = item.set_hover(event) + if draw: + self.figure.canvas.draw() + break - if draw: - print 'draw' - self.figure.canvas.draw() - fig = plt.figure() -menu = Menu(fig, ('open', 'close', 'save', 'save as', 'quit')) +fig.subplots_adjust(left=0.3) +props = ItemProperties(labelcolor='black', bgcolor='yellow', + fontsize=15, alpha=0.2) +hoverprops = ItemProperties(labelcolor='white', bgcolor='blue', + fontsize=15, alpha=0.2) +menuitems = [] +for label in ('open', 'close', 'save', 'save as', 'quit'): + def on_select(item): + print 'you selected', item.labelstr + item = MenuItem(fig, label, props=props, hoverprops=hoverprops, on_select=on_select) + menuitems.append(item) + +menu = Menu(fig, menuitems) plt.show() Modified: trunk/matplotlib/lib/matplotlib/axes.py =================================================================== --- trunk/matplotlib/lib/matplotlib/axes.py 2008-07-02 15:36:38 UTC (rev 5706) +++ trunk/matplotlib/lib/matplotlib/axes.py 2008-07-03 13:21:54 UTC (rev 5707) @@ -813,8 +813,9 @@ a.set_figure(self.figure) if not a.is_transform_set(): a.set_transform(self.transData) - a.axes = self + a.set_axes(self) + def _gen_axes_patch(self): """ Returns the patch used to draw the background of the axes. It Modified: trunk/matplotlib/lib/matplotlib/pyplot.py =================================================================== --- trunk/matplotlib/lib/matplotlib/pyplot.py 2008-07-02 15:36:38 UTC (rev 5706) +++ trunk/matplotlib/lib/matplotlib/pyplot.py 2008-07-03 13:21:54 UTC (rev 5707) @@ -202,6 +202,14 @@ frameon=frameon, FigureClass=FigureClass, **kwargs) + + # make this figure current on button press event + def make_active(event): + _pylab_helpers.Gcf.set_active(figManager) + + cid = figManager.canvas.mpl_connect('button_press_event', make_active) + figManager._cidgcf = cid + _pylab_helpers.Gcf.set_active(figManager) figManager.canvas.figure.number = num @@ -252,17 +260,21 @@ if len(args)==0: figManager = _pylab_helpers.Gcf.get_active() if figManager is None: return - else: _pylab_helpers.Gcf.destroy(figManager.num) + else: + figManager.canvas.mpl_disconnect(figManager._cidgcf) + _pylab_helpers.Gcf.destroy(figManager.num) elif len(args)==1: arg = args[0] if arg=='all': for manager in _pylab_helpers.Gcf.get_all_fig_managers(): + manager.canvas.mpl_disconnect(manager._cidgcf) _pylab_helpers.Gcf.destroy(manager.num) elif isinstance(arg, int): _pylab_helpers.Gcf.destroy(arg) elif isinstance(arg, Figure): for manager in _pylab_helpers.Gcf.get_all_fig_managers(): if manager.canvas.figure==arg: + manager.canvas.mpl_disconnect(manager._cidgcf) _pylab_helpers.Gcf.destroy(manager.num) else: raise TypeError('Unrecognized argument type %s to close'%type(arg)) Modified: trunk/matplotlib/src/_backend_agg.cpp =================================================================== --- trunk/matplotlib/src/_backend_agg.cpp 2008-07-02 15:36:38 UTC (rev 5706) +++ trunk/matplotlib/src/_backend_agg.cpp 2008-07-03 13:21:54 UTC (rev 5707) @@ -90,6 +90,20 @@ return Py::String(PyString_FromStringAndSize((const char*)data, height*stride), true); } +Py::Object BufferRegion::set_x(const Py::Tuple &args) { + args.verify_length(1); + size_t x = Py::Int( args[0] ); + rect.x1 = x; + return Py::Object(); +} + +Py::Object BufferRegion::set_y(const Py::Tuple &args) { + args.verify_length(1); + size_t y = Py::Int( args[0] ); + rect.y1 = y; + return Py::Object(); +} + Py::Object BufferRegion::to_string_argb(const Py::Tuple &args) { // owned=true to prevent memory leak Py_ssize_t length; @@ -1608,6 +1622,13 @@ behaviors().name("BufferRegion"); behaviors().doc("A wrapper to pass agg buffer objects to and from the python level"); + + add_varargs_method("set_x", &BufferRegion::set_x, + "set_x(x)"); + + add_varargs_method("set_y", &BufferRegion::set_y, + "set_y(y)"); + add_varargs_method("to_string", &BufferRegion::to_string, "to_string()"); add_varargs_method("to_string_argb", &BufferRegion::to_string_argb, Modified: trunk/matplotlib/src/_backend_agg.h =================================================================== --- trunk/matplotlib/src/_backend_agg.h 2008-07-02 15:36:38 UTC (rev 5706) +++ trunk/matplotlib/src/_backend_agg.h 2008-07-03 13:21:54 UTC (rev 5707) @@ -102,6 +102,10 @@ bool freemem; + // set the x and y corners of the rectangle + Py::Object set_x(const Py::Tuple &args); + Py::Object set_y(const Py::Tuple &args); + Py::Object to_string(const Py::Tuple &args); Py::Object to_string_argb(const Py::Tuple &args); static void init_type(void); Modified: trunk/matplotlib/unit/memleak_hawaii3.py =================================================================== --- trunk/matplotlib/unit/memleak_hawaii3.py 2008-07-02 15:36:38 UTC (rev 5706) +++ trunk/matplotlib/unit/memleak_hawaii3.py 2008-07-03 13:21:54 UTC (rev 5707) @@ -2,15 +2,15 @@ import os, sys, time, gc import matplotlib -matplotlib.use('Agg') +matplotlib.use('PDF') from matplotlib.cbook import report_memory -import matplotlib.numerix as nx +import numpy as np from pylab import figure, show, close # take a memory snapshot on indStart and compare it with indEnd -rand = nx.mlab.rand +rand = np.mlab.rand indStart, indEnd = 200, 401 for i in range(indEnd): @@ -19,8 +19,8 @@ fig.clf() - t1 = nx.arange(0.0, 2.0, 0.01) - y1 = nx.sin(2*nx.pi*t1) + t1 = np.arange(0.0, 2.0, 0.01) + y1 = np.sin(2*np.pi*t1) y2 = rand(len(t1)) X = rand(50,50) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jd...@us...> - 2008-07-03 13:38:59
|
Revision: 5708 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5708&view=rev Author: jdh2358 Date: 2008-07-03 06:38:52 -0700 (Thu, 03 Jul 2008) Log Message: ----------- fixed text picking Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/text.py Added Paths: ----------- trunk/matplotlib/examples/api/line_with_text.py Added: trunk/matplotlib/examples/api/line_with_text.py =================================================================== --- trunk/matplotlib/examples/api/line_with_text.py (rev 0) +++ trunk/matplotlib/examples/api/line_with_text.py 2008-07-03 13:38:52 UTC (rev 5708) @@ -0,0 +1,65 @@ +""" +Show how to override basic methods so an artist can contain another +artist. In this case, the line contains a Text instance to label it. +""" +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.lines as lines +import matplotlib.transforms as mtransforms +import matplotlib.text as mtext + + +class MyLine(lines.Line2D): + + def __init__(self, *args, **kwargs): + # we'll update the position when the line data is set + self.text = mtext.Text(0, 0, '') + lines.Line2D.__init__(self, *args, **kwargs) + + # we can't access the label attr until *after* the line is + # inited + self.text.set_text(self.get_label()) + + def set_figure(self, figure): + self.text.set_figure(figure) + lines.Line2D.set_figure(self, figure) + + def set_axes(self, axes): + self.text.set_axes(axes) + lines.Line2D.set_axes(self, axes) + + def set_transform(self, transform): + # 2 pixel offset + texttrans = transform + mtransforms.Affine2D().translate(2, 2) + self.text.set_transform(texttrans) + lines.Line2D.set_transform(self, transform) + + + def set_data(self, x, y): + if len(x): + self.text.set_position((x[-1], y[-1])) + + lines.Line2D.set_data(self, x, y) + + def draw(self, renderer): + # draw my label at the end of the line with 2 pixel offset + lines.Line2D.draw(self, renderer) + self.text.draw(renderer) + + + + + +fig = plt.figure() +ax = fig.add_subplot(111) +x, y = np.random.rand(2, 20) +line = MyLine(x, y, mfc='red', ms=12, label='line label') +#line.text.set_text('line label') +line.text.set_color('red') +line.text.set_fontsize(16) + + +ax.add_line(line) + + +plt.show() Modified: trunk/matplotlib/lib/matplotlib/text.py =================================================================== --- trunk/matplotlib/lib/matplotlib/text.py 2008-07-03 13:21:54 UTC (rev 5707) +++ trunk/matplotlib/lib/matplotlib/text.py 2008-07-03 13:38:52 UTC (rev 5708) @@ -135,17 +135,15 @@ """ if callable(self._contains): return self._contains(self,mouseevent) - try: - l,b,w,h = self.get_window_extent().get_bounds() - except: - # TODO: why does this error occur - #print str(self),"error looking at get_window_extent" - return False,{} + + l,b,w,h = self.get_window_extent().bounds + r = l+w t = b+h xyverts = (l,b), (l, t), (r, t), (r, b) x, y = mouseevent.x, mouseevent.y inside = nxutils.pnpoly(x, y, xyverts) + return inside,{} def _get_xy_display(self): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jd...@us...> - 2008-07-03 14:30:16
|
Revision: 5709 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5709&view=rev Author: jdh2358 Date: 2008-07-03 07:30:13 -0700 (Thu, 03 Jul 2008) Log Message: ----------- added findobj Modified Paths: -------------- trunk/matplotlib/CHANGELOG trunk/matplotlib/lib/matplotlib/artist.py trunk/matplotlib/lib/matplotlib/cbook.py trunk/matplotlib/lib/matplotlib/legend.py trunk/matplotlib/lib/matplotlib/pylab.py trunk/matplotlib/lib/matplotlib/pyplot.py Added Paths: ----------- trunk/matplotlib/examples/pylab_examples/findobj_demo.py Modified: trunk/matplotlib/CHANGELOG =================================================================== --- trunk/matplotlib/CHANGELOG 2008-07-03 13:38:52 UTC (rev 5708) +++ trunk/matplotlib/CHANGELOG 2008-07-03 14:30:13 UTC (rev 5709) @@ -1,3 +1,6 @@ +2007-07-03 Implemented findobj method for artist and pyplot - see + examples/pylab_examples/findobj_demo.py - JDH + 2008-06-30 Another attempt to fix TextWithDash - DSD 2008-06-30 Removed Qt4 NavigationToolbar2.destroy -- it appears to Added: trunk/matplotlib/examples/pylab_examples/findobj_demo.py =================================================================== --- trunk/matplotlib/examples/pylab_examples/findobj_demo.py (rev 0) +++ trunk/matplotlib/examples/pylab_examples/findobj_demo.py 2008-07-03 14:30:13 UTC (rev 5709) @@ -0,0 +1,34 @@ +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.text as text + +a = np.arange(0,3,.02) +b = np.arange(0,3,.02) +c = np.exp(a) +d = c[::-1] + +fig = plt.figure() +ax = fig.add_subplot(111) +plt.plot(a,c,'k--',a,d,'k:',a,c+d,'k') +plt.legend(('Model length', 'Data length', 'Total message length'), + 'upper center', shadow=True) +plt.ylim([-1,20]) +plt.grid(False) +plt.xlabel('Model complexity --->') +plt.ylabel('Message length --->') +plt.title('Minimum Message Length') + +# match on arbitrary function +def myfunc(x): + return hasattr(x, 'set_color') + +for o in fig.findobj(myfunc): + o.set_color('blue') + +# match on class instances +for o in fig.findobj(text.Text): + o.set_fontstyle('italic') + + + +plt.show() Modified: trunk/matplotlib/lib/matplotlib/artist.py =================================================================== --- trunk/matplotlib/lib/matplotlib/artist.py 2008-07-03 13:38:52 UTC (rev 5708) +++ trunk/matplotlib/lib/matplotlib/artist.py 2008-07-03 14:30:13 UTC (rev 5709) @@ -508,7 +508,47 @@ ret.extend( [func(v)] ) return ret + def findobj(self, match=None): + """ + recursively find all :class:matplotlib.artist.Artist instances + contained in self + *match* can be + + - None: return all objects contained in artist (including artist) + + - function with signature ``boolean = match(artist)`` used to filter matches + + - class instance: eg Line2D. Only return artists of class type + """ + + if match is None: # always return True + def matchfunc(x): return True + elif cbook.issubclass_safe(match, Artist): + def matchfunc(x): + return isinstance(x, match) + elif callable(match): + matchfunc = match + else: + raise ValueError('match must be None, an matplotlib.artist.Artist subclass, or a callable') + + + artists = [] + if hasattr(self, 'get_children'): + for c in self.get_children(): + if matchfunc(c): + artists.append(c) + artists.extend([thisc for thisc in c.findobj(matchfunc) if matchfunc(thisc)]) + else: + if matchfunc(self): + artists.append(self) + return artists + + + + + + class ArtistInspector: """ A helper class to inspect an :class:`~matplotlib.artist.Artist` @@ -690,6 +730,48 @@ return lines + + def findobj(self, match=None): + """ + recursively find all :class:matplotlib.artist.Artist instances + contained in self + + if *match* is not None, it can be + + - function with signature ``boolean = match(artist)`` + + - class instance: eg Line2D + + used to filter matches + """ + + if match is None: # always return True + def matchfunc(x): return True + elif issubclass(match, Artist): + def matchfunc(x): + return isinstance(x, match) + elif callable(match): + matchfunc = func + else: + raise ValueError('match must be None, an matplotlib.artist.Artist subclass, or a callable') + + + artists = [] + if hasattr(self, 'get_children'): + for c in self.get_children(): + if matchfunc(c): + artists.append(c) + artists.extend([thisc for thisc in c.findobj(matchfunc) if matchfunc(thisc)]) + else: + if matchfunc(self): + artists.append(self) + return artists + + + + + + def getp(o, property=None): """ Return the value of handle property. property is an optional string Modified: trunk/matplotlib/lib/matplotlib/cbook.py =================================================================== --- trunk/matplotlib/lib/matplotlib/cbook.py 2008-07-03 13:38:52 UTC (rev 5708) +++ trunk/matplotlib/lib/matplotlib/cbook.py 2008-07-03 14:30:13 UTC (rev 5709) @@ -886,7 +886,14 @@ raise ValueError(_safezip_msg % (Nx, i+1, len(arg))) return zip(*args) +def issubclass_safe(x, klass): + 'return issubclass(x, klass) and return False on a TypeError' + try: + return issubclass(x, klass) + except TypeError: + return False + class MemoryMonitor: def __init__(self, nmax=20000): self._nmax = nmax Modified: trunk/matplotlib/lib/matplotlib/legend.py =================================================================== --- trunk/matplotlib/lib/matplotlib/legend.py 2008-07-03 13:38:52 UTC (rev 5708) +++ trunk/matplotlib/lib/matplotlib/legend.py 2008-07-03 14:30:13 UTC (rev 5709) @@ -363,6 +363,12 @@ 'b is a boolean. Set draw frame to b' self._drawFrame = b + def get_children(self): + children = [] + children.extend(self.legendHandles) + children.extend(self.texts) + return children + def get_frame(self): 'return the Rectangle instance used to frame the legend' return self.legendPatch Modified: trunk/matplotlib/lib/matplotlib/pylab.py =================================================================== --- trunk/matplotlib/lib/matplotlib/pylab.py 2008-07-03 13:38:52 UTC (rev 5708) +++ trunk/matplotlib/lib/matplotlib/pylab.py 2008-07-03 14:30:13 UTC (rev 5709) @@ -38,6 +38,7 @@ figtext - add text in figure coords figure - create or change active figure fill - make filled polygons + findobj - recursively find all objects matching some criteria gca - return the current axes gcf - return the current figure gci - get the current image, or None Modified: trunk/matplotlib/lib/matplotlib/pyplot.py =================================================================== --- trunk/matplotlib/lib/matplotlib/pyplot.py 2008-07-03 13:38:52 UTC (rev 5708) +++ trunk/matplotlib/lib/matplotlib/pyplot.py 2008-07-03 14:30:13 UTC (rev 5709) @@ -38,6 +38,29 @@ from matplotlib.backends import pylab_setup new_figure_manager, draw_if_interactive, show = pylab_setup() + + +def findobj(o=None, match=None): + """ + recursively find all :class:matplotlib.artist.Artist instances + contained in artist instance *p*. if *o* is None, use + current figure + + *match* can be + + - None: return all objects contained in artist (including artist) + + - function with signature ``boolean = match(artist)`` used to filter matches + + - class instance: eg Line2D. Only return artists of class type + + """ + + if o is None: + o = gcf() + return o.findobj(match) + + def switch_backend(newbackend): """ Switch the default backend to newbackend. This feature is This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sa...@us...> - 2008-07-07 17:37:58
|
Revision: 5715 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5715&view=rev Author: sameerd Date: 2008-07-07 10:37:33 -0700 (Mon, 07 Jul 2008) Log Message: ----------- bug fixes - edgecases Modified Paths: -------------- trunk/matplotlib/examples/misc/rec_join_demo.py trunk/matplotlib/lib/matplotlib/mlab.py Modified: trunk/matplotlib/examples/misc/rec_join_demo.py =================================================================== --- trunk/matplotlib/examples/misc/rec_join_demo.py 2008-07-07 12:12:52 UTC (rev 5714) +++ trunk/matplotlib/examples/misc/rec_join_demo.py 2008-07-07 17:37:33 UTC (rev 5715) @@ -2,7 +2,7 @@ import matplotlib.mlab as mlab -r = mlab.csv2rec('data/aapl.csv') +r = mlab.csv2rec('../data/aapl.csv') r.sort() r1 = r[-10:] Modified: trunk/matplotlib/lib/matplotlib/mlab.py =================================================================== --- trunk/matplotlib/lib/matplotlib/mlab.py 2008-07-07 12:12:52 UTC (rev 5714) +++ trunk/matplotlib/lib/matplotlib/mlab.py 2008-07-07 17:37:33 UTC (rev 5715) @@ -2081,10 +2081,12 @@ def rec_join(key, r1, r2, jointype='inner', defaults=None): """ join record arrays r1 and r2 on key; key is a tuple of field - names. if r1 and r2 have equal values on all the keys in the key + names. If r1 and r2 have equal values on all the keys in the key tuple, then their fields will be merged into a new record array - containing the intersection of the fields of r1 and r2 + containing the intersection of the fields of r1 and r2. + r1 (also r2) must not have any duplicate keys. + The jointype keyword can be 'inner', 'outer', 'leftouter'. To do a rightouter join just reverse r1 and r2. @@ -2123,9 +2125,6 @@ right_ind = np.array([r2d[k] for k in right_keys]) right_len = len(right_ind) - r2 = rec_drop_fields(r2, r1.dtype.names) - - def key_desc(name): 'if name is a string key, use the larger size of r1 or r2 before merging' dt1 = r1.dtype[name] @@ -2158,21 +2157,17 @@ for field in r1.dtype.names: newrec[field][:common_len] = r1[field][r1ind] - if jointype == "outer" or jointype == "leftouter": + if (jointype == "outer" or jointype == "leftouter") and left_len: newrec[field][common_len:(common_len+left_len)] = r1[field][left_ind] for field in r2.dtype.names: - newrec[field][:common_len] = r2[field][r2ind] - if jointype == "outer": - newrec[field][-right_len:] = r2[field][right_ind[right_ind.argsort()]] + if field not in key: + newrec[field][:common_len] = r2[field][r2ind] + if jointype == "outer" and right_len: + newrec[field][-right_len:] = r2[field][right_ind] - # sort newrec using the same order as r1 - sort_indices = r1ind.copy() - if jointype == "outer" or jointype == "leftouter": - sort_indices = np.append(sort_indices, left_ind) - newrec[:(common_len+left_len)] = newrec[sort_indices.argsort()] + newrec.sort(order=key) - return newrec.view(np.recarray) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <md...@us...> - 2008-07-07 17:48:50
|
Revision: 5716 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5716&view=rev Author: mdboom Date: 2008-07-07 10:48:36 -0700 (Mon, 07 Jul 2008) Log Message: ----------- Fix custom scales in pcolormesh (thanks, Matthew Turk) Modified Paths: -------------- trunk/matplotlib/examples/pylab_examples/quadmesh_demo.py trunk/matplotlib/lib/matplotlib/collections.py Modified: trunk/matplotlib/examples/pylab_examples/quadmesh_demo.py =================================================================== --- trunk/matplotlib/examples/pylab_examples/quadmesh_demo.py 2008-07-07 17:37:33 UTC (rev 5715) +++ trunk/matplotlib/examples/pylab_examples/quadmesh_demo.py 2008-07-07 17:48:36 UTC (rev 5716) @@ -29,6 +29,8 @@ ax = fig.add_subplot(121) ax.set_axis_bgcolor("#bdb76b") ax.pcolormesh(Qx,Qz,Z) +ax.set_xscale('log') +ax.set_yscale('log') ax.set_title('Without masked values') ax = fig.add_subplot(122) Modified: trunk/matplotlib/lib/matplotlib/collections.py =================================================================== --- trunk/matplotlib/lib/matplotlib/collections.py 2008-07-07 17:37:33 UTC (rev 5715) +++ trunk/matplotlib/lib/matplotlib/collections.py 2008-07-07 17:48:36 UTC (rev 5716) @@ -512,14 +512,24 @@ if clippath_trans is not None: clippath_trans = clippath_trans.frozen() - assert transform.is_affine + if not transform.is_affine: + coordinates = self._coordinates.reshape( + (self._coordinates.shape[0] * + self._coordinates.shape[1], + 2)) + coordinates = transform.transform(coordinates) + coordinates = coordinates.reshape(self._coordinates.shape) + transform = transforms.IdentityTransform() + else: + coordinates = self._coordinates + if not transOffset.is_affine: offsets = transOffset.transform_non_affine(offsets) transOffset = transOffset.get_affine() renderer.draw_quad_mesh( transform.frozen(), self.clipbox, clippath, clippath_trans, - self._meshWidth, self._meshHeight, self._coordinates, + self._meshWidth, self._meshHeight, coordinates, offsets, transOffset, self._facecolors, self._antialiased, self._showedges) renderer.close_group(self.__class__.__name__) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <md...@us...> - 2008-07-08 14:57:03
|
Revision: 5721 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5721&view=rev Author: mdboom Date: 2008-07-08 07:55:33 -0700 (Tue, 08 Jul 2008) Log Message: ----------- Merged revisions 5685-5720 via svnmerge from https://matplotlib.svn.sf.net/svnroot/matplotlib/branches/v0_91_maint ........ r5700 | dsdale | 2008-06-30 09:24:13 -0400 (Mon, 30 Jun 2008) | 2 lines removed Qt4's NavigationToolbar2.destroy method ........ r5706 | mdboom | 2008-07-02 11:36:38 -0400 (Wed, 02 Jul 2008) | 2 lines Fix bug using autolegend with LineCollection. ........ r5720 | mdboom | 2008-07-08 10:50:20 -0400 (Tue, 08 Jul 2008) | 2 lines Improve mathtext superscript placement. ........ Modified Paths: -------------- trunk/matplotlib/CHANGELOG trunk/matplotlib/lib/matplotlib/mathtext.py Property Changed: ---------------- trunk/matplotlib/ Property changes on: trunk/matplotlib ___________________________________________________________________ Name: svnmerge-integrated - /branches/v0_91_maint:1-5684 + /branches/v0_91_maint:1-5720 Modified: trunk/matplotlib/CHANGELOG =================================================================== --- trunk/matplotlib/CHANGELOG 2008-07-08 14:50:20 UTC (rev 5720) +++ trunk/matplotlib/CHANGELOG 2008-07-08 14:55:33 UTC (rev 5721) @@ -1,3 +1,5 @@ +2008-07-08 Improve mathtext superscript placement - MGD + 2008-07-07 Fix custom scales in pcolormesh (thanks Matthew Turk) - MGD 2008-07-03 Implemented findobj method for artist and pyplot - see Modified: trunk/matplotlib/lib/matplotlib/mathtext.py =================================================================== --- trunk/matplotlib/lib/matplotlib/mathtext.py 2008-07-08 14:50:20 UTC (rev 5720) +++ trunk/matplotlib/lib/matplotlib/mathtext.py 2008-07-08 14:55:33 UTC (rev 5721) @@ -1169,7 +1169,7 @@ # Percentage of x-height that sub/superscripts drop below the baseline SUBDROP = 0.3 # Percentage of x-height that superscripts drop below the baseline -SUP1 = 0.7 +SUP1 = 0.5 # Percentage of x-height that subscripts drop below the baseline SUB1 = 0.0 # Percentage of x-height that superscripts are offset relative to the subscript This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <md...@us...> - 2008-07-09 13:39:50
|
Revision: 5724 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5724&view=rev Author: mdboom Date: 2008-07-09 06:39:36 -0700 (Wed, 09 Jul 2008) Log Message: ----------- Merged revisions 5721-5723 via svnmerge from https://matplotlib.svn.sf.net/svnroot/matplotlib/branches/v0_91_maint ........ r5723 | mdboom | 2008-07-09 09:33:13 -0400 (Wed, 09 Jul 2008) | 2 lines Improve mathtext radical rendering ........ Modified Paths: -------------- trunk/matplotlib/CHANGELOG trunk/matplotlib/lib/matplotlib/mathtext.py Property Changed: ---------------- trunk/matplotlib/ Property changes on: trunk/matplotlib ___________________________________________________________________ Name: svnmerge-integrated - /branches/v0_91_maint:1-5720 + /branches/v0_91_maint:1-5723 Modified: trunk/matplotlib/CHANGELOG =================================================================== --- trunk/matplotlib/CHANGELOG 2008-07-09 13:33:13 UTC (rev 5723) +++ trunk/matplotlib/CHANGELOG 2008-07-09 13:39:36 UTC (rev 5724) @@ -1,3 +1,5 @@ +2008-07-09 Improve mathtext radical rendering - MGD + 2008-07-08 Improve mathtext superscript placement - MGD 2008-07-07 Fix custom scales in pcolormesh (thanks Matthew Turk) - MGD Modified: trunk/matplotlib/lib/matplotlib/mathtext.py =================================================================== --- trunk/matplotlib/lib/matplotlib/mathtext.py 2008-07-09 13:33:13 UTC (rev 5723) +++ trunk/matplotlib/lib/matplotlib/mathtext.py 2008-07-09 13:39:36 UTC (rev 5724) @@ -322,7 +322,13 @@ self.image, ox, oy - info.metrics.ymax, info.glyph) def render_rect_filled(self, x1, y1, x2, y2): - self.image.draw_rect_filled(x1, y1, x2, max(y2 - 1, y1)) + height = max(int(y2 - y1) - 1, 0) + if height == 0: + center = (y2 + y1) / 2.0 + y = int(center - (height + 1) / 2.0) + else: + y = int(y1) + self.image.draw_rect_filled(int(x1), y, ceil(x2), y + height) def get_results(self, box): return (self.ox, @@ -481,8 +487,8 @@ to be destroyed.""" self.used_characters = None - def get_kern(self, font1, sym1, fontsize1, - font2, sym2, fontsize2, dpi): + def get_kern(self, font1, fontclass1, sym1, fontsize1, + font2, fontclass2, sym2, fontsize2, dpi): """ Get the kerning distance for font between sym1 and sym2. @@ -670,7 +676,8 @@ info2 = self._get_info(font2, fontclass2, sym2, fontsize2, dpi) font = info1.font return font.get_kerning(info1.num, info2.num, KERNING_DEFAULT) / 64.0 - return 0.0 + return Fonts.get_kern(self, font1, fontclass1, sym1, fontsize1, + font2, fontclass2, sym2, fontsize2, dpi) class BakomaFonts(TruetypeFonts): """ @@ -1123,7 +1130,8 @@ font = info1.font return (font.get_kern_dist(info1.glyph, info2.glyph) * 0.001 * fontsize1) - return 0.0 + return Fonts.get_kern(self, font1, fontclass1, sym1, fontsize1, + font2, fontclass2, sym2, fontsize2, dpi) def get_xheight(self, font, fontsize, dpi): cached_font = self._get_font(font) @@ -1433,6 +1441,19 @@ new_children.append(kern) self.children = new_children + # This is a failed experiment to fake cross-font kerning. +# def get_kerning(self, next): +# if len(self.children) >= 2 and isinstance(self.children[-2], Char): +# if isinstance(next, Char): +# print "CASE A" +# return self.children[-2].get_kerning(next) +# elif isinstance(next, Hlist) and len(next.children) and isinstance(next.children[0], Char): +# print "CASE B" +# result = self.children[-2].get_kerning(next.children[0]) +# print result +# return result +# return 0.0 + def hpack(self, w=0., m='additional'): """The main duty of hpack is to compute the dimensions of the resulting boxes, and to adjust the glue if one of those dimensions is @@ -2593,13 +2614,6 @@ thickness = state.font_output.get_underline_thickness( state.font, state.fontsize, state.dpi) - if root is None: - root = Box(0., 0., 0.) - else: - root = Hlist([Char(x, state) for x in root]) - root.shrink() - root.shrink() - # Determine the height of the body, and add a little extra to # the height so it doesn't seem cramped height = body.height - body.shift_amount + thickness * 5.0 @@ -2616,10 +2630,18 @@ Fill(), padded_body]) # Stretch the glue between the hrule and the body - rightside.vpack(height + 1.0, depth, 'exactly') + rightside.vpack(height + (state.fontsize * state.dpi) / (100.0 * 12.0), + depth, 'exactly') # Add the root and shift it upward so it is above the tick. # The value of 0.6 is a hard-coded hack ;) + if root is None: + root = Box(check.width * 0.5, 0., 0.) + else: + root = Hlist([Char(x, state) for x in root]) + root.shrink() + root.shrink() + root_vlist = Vlist([Hlist([root])]) root_vlist.shift_amount = -height * 0.6 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <md...@us...> - 2008-07-09 19:30:24
|
Revision: 5727 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5727&view=rev Author: mdboom Date: 2008-07-09 12:30:22 -0700 (Wed, 09 Jul 2008) Log Message: ----------- Fix rectangular polar axes patch. Modified Paths: -------------- trunk/matplotlib/CHANGELOG trunk/matplotlib/lib/matplotlib/projections/geo.py trunk/matplotlib/lib/matplotlib/projections/polar.py Modified: trunk/matplotlib/CHANGELOG =================================================================== --- trunk/matplotlib/CHANGELOG 2008-07-09 16:16:50 UTC (rev 5726) +++ trunk/matplotlib/CHANGELOG 2008-07-09 19:30:22 UTC (rev 5727) @@ -1,3 +1,5 @@ +2008-07-09 Fix rectangular axes patch on polar plots bug - MGD + 2008-07-09 Improve mathtext radical rendering - MGD 2008-07-08 Improve mathtext superscript placement - MGD Modified: trunk/matplotlib/lib/matplotlib/projections/geo.py =================================================================== --- trunk/matplotlib/lib/matplotlib/projections/geo.py 2008-07-09 16:16:50 UTC (rev 5726) +++ trunk/matplotlib/lib/matplotlib/projections/geo.py 2008-07-09 19:30:22 UTC (rev 5727) @@ -127,7 +127,7 @@ def get_yaxis_text2_transform(self, pad): return self._yaxis_text2_transform, 'center', 'left' - def get_axes_patch(self): + def _gen_axes_patch(self): return Circle((0.5, 0.5), 0.5) def set_yscale(self, *args, **kwargs): Modified: trunk/matplotlib/lib/matplotlib/projections/polar.py =================================================================== --- trunk/matplotlib/lib/matplotlib/projections/polar.py 2008-07-09 16:16:50 UTC (rev 5726) +++ trunk/matplotlib/lib/matplotlib/projections/polar.py 2008-07-09 19:30:22 UTC (rev 5727) @@ -261,7 +261,7 @@ def get_yaxis_text2_transform(self, pad): return self._yaxis_text2_transform, 'center', 'center' - def get_axes_patch(self): + def _gen_axes_patch(self): return Circle((0.5, 0.5), 0.5) def set_rmax(self, rmax): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <md...@us...> - 2008-07-10 14:07:03
|
Revision: 5730 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5730&view=rev Author: mdboom Date: 2008-07-10 07:07:00 -0700 (Thu, 10 Jul 2008) Log Message: ----------- [ 2014183 ] multiple imshow() causes gray edges Modified Paths: -------------- trunk/matplotlib/CHANGELOG trunk/matplotlib/lib/matplotlib/backends/backend_agg.py trunk/matplotlib/src/_image.cpp Modified: trunk/matplotlib/CHANGELOG =================================================================== --- trunk/matplotlib/CHANGELOG 2008-07-10 12:22:16 UTC (rev 5729) +++ trunk/matplotlib/CHANGELOG 2008-07-10 14:07:00 UTC (rev 5730) @@ -1,3 +1,5 @@ +2008-07-10 Bugfix: [ 2014183 ] multiple imshow() causes gray edges - MGD + 2008-07-09 Fix rectangular axes patch on polar plots bug - MGD 2008-07-09 Improve mathtext radical rendering - MGD Modified: trunk/matplotlib/lib/matplotlib/backends/backend_agg.py =================================================================== --- trunk/matplotlib/lib/matplotlib/backends/backend_agg.py 2008-07-10 12:22:16 UTC (rev 5729) +++ trunk/matplotlib/lib/matplotlib/backends/backend_agg.py 2008-07-10 14:07:00 UTC (rev 5730) @@ -211,6 +211,11 @@ def clear(self): self._renderer.clear() + def option_image_nocomposite(self): + # It is generally faster to composite each image directly to + # the Figure, and there's no file size benefit to compositing + # with the Agg backend + return True def new_figure_manager(num, *args, **kwargs): Modified: trunk/matplotlib/src/_image.cpp =================================================================== --- trunk/matplotlib/src/_image.cpp 2008-07-10 12:22:16 UTC (rev 5729) +++ trunk/matplotlib/src/_image.cpp 2008-07-10 14:07:00 UTC (rev 5730) @@ -742,7 +742,7 @@ //clear the background of the rendering buffer with alpha 1 and the //gtkagg screen noise problem in figimage_demo.py goes away -- see //comment backend_gtkagg.py _render_figure method JDH - //rb.clear(agg::rgba(1, 1, 1, 1)); + rb.clear(agg::rgba(1, 1, 1, 1)); for (size_t imnum=0; imnum< N; imnum++) { tup = Py::Tuple(tups[imnum]); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <md...@us...> - 2008-07-10 14:13:11
|
Revision: 5731 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5731&view=rev Author: mdboom Date: 2008-07-10 07:13:07 -0700 (Thu, 10 Jul 2008) Log Message: ----------- [ 2013963 ] update_datalim_bounds in Axes not works Modified Paths: -------------- trunk/matplotlib/CHANGELOG trunk/matplotlib/lib/matplotlib/axes.py Modified: trunk/matplotlib/CHANGELOG =================================================================== --- trunk/matplotlib/CHANGELOG 2008-07-10 14:07:00 UTC (rev 5730) +++ trunk/matplotlib/CHANGELOG 2008-07-10 14:13:07 UTC (rev 5731) @@ -1,3 +1,5 @@ +2008-07-10 Bugfix: [ 2013963 ] update_datalim_bounds in Axes not works - MGD + 2008-07-10 Bugfix: [ 2014183 ] multiple imshow() causes gray edges - MGD 2008-07-09 Fix rectangular axes patch on polar plots bug - MGD Modified: trunk/matplotlib/lib/matplotlib/axes.py =================================================================== --- trunk/matplotlib/lib/matplotlib/axes.py 2008-07-10 14:07:00 UTC (rev 5730) +++ trunk/matplotlib/lib/matplotlib/axes.py 2008-07-10 14:13:07 UTC (rev 5731) @@ -1394,7 +1394,7 @@ Update the datalim to include the given :class:`~matplotlib.transforms.Bbox` *bounds* ''' - self.dataLim.set(Bbox.union([self.dataLim, bounds])) + self.dataLim.set(mtransforms.Bbox.union([self.dataLim, bounds])) def _process_unit_info(self, xdata=None, ydata=None, kwargs=None): 'look for unit *kwargs* and update the axis instances as necessary' This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <md...@us...> - 2008-07-10 15:45:49
|
Revision: 5732 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5732&view=rev Author: mdboom Date: 2008-07-10 08:45:15 -0700 (Thu, 10 Jul 2008) Log Message: ----------- Bugfix: crash displaying fontconfig pattern Modified Paths: -------------- trunk/matplotlib/CHANGELOG trunk/matplotlib/lib/matplotlib/fontconfig_pattern.py Modified: trunk/matplotlib/CHANGELOG =================================================================== --- trunk/matplotlib/CHANGELOG 2008-07-10 14:13:07 UTC (rev 5731) +++ trunk/matplotlib/CHANGELOG 2008-07-10 15:45:15 UTC (rev 5732) @@ -1,3 +1,5 @@ +2008-07-10 Bugfix: crash displaying fontconfig pattern - MGD + 2008-07-10 Bugfix: [ 2013963 ] update_datalim_bounds in Axes not works - MGD 2008-07-10 Bugfix: [ 2014183 ] multiple imshow() causes gray edges - MGD Modified: trunk/matplotlib/lib/matplotlib/fontconfig_pattern.py =================================================================== --- trunk/matplotlib/lib/matplotlib/fontconfig_pattern.py 2008-07-10 14:13:07 UTC (rev 5731) +++ trunk/matplotlib/lib/matplotlib/fontconfig_pattern.py 2008-07-10 15:45:15 UTC (rev 5732) @@ -123,23 +123,23 @@ return props def _family(self, s, loc, tokens): - return [family_unescape(r'\1', tokens[0])] + return [family_unescape(r'\1', str(tokens[0]))] def _size(self, s, loc, tokens): return [float(tokens[0])] def _name(self, s, loc, tokens): - return [tokens[0]] + return [str(tokens[0])] def _value(self, s, loc, tokens): - return [value_unescape(r'\1', tokens[0])] + return [value_unescape(r'\1', str(tokens[0]))] def _families(self, s, loc, tokens): - self._properties['family'] = tokens + self._properties['family'] = [str(x) for x in tokens] return [] def _point_sizes(self, s, loc, tokens): - self._properties['size'] = tokens + self._properties['size'] = [str(x) for x in tokens] return [] def _property(self, s, loc, tokens): @@ -161,10 +161,13 @@ props = [] families = '' size = '' - for key, val in d.items(): + for key in 'family style variant weight stretch file size'.split(): + val = getattr(d, 'get_' + key)() if val is not None and val != []: - val = [value_escape(r'\\\1', str(x)) for x in val if x is not None] - if val != []: - val = ','.join(val) - props.append(":%s=%s" % (key, val)) + if type(val) == list: + val = [value_escape(r'\\\1', str(x)) for x in val if x is not None] + if val != []: + val = ','.join(val) + props.append(":%s=%s" % (key, val)) + print parse_fontconfig_pattern(''.join(props)) return ''.join(props) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <md...@us...> - 2008-07-11 18:21:57
|
Revision: 5747 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5747&view=rev Author: mdboom Date: 2008-07-11 11:21:53 -0700 (Fri, 11 Jul 2008) Log Message: ----------- Fix memory leak when using shared axes. Modified Paths: -------------- trunk/matplotlib/CHANGELOG trunk/matplotlib/lib/matplotlib/axes.py trunk/matplotlib/lib/matplotlib/cbook.py Modified: trunk/matplotlib/CHANGELOG =================================================================== --- trunk/matplotlib/CHANGELOG 2008-07-11 16:30:07 UTC (rev 5746) +++ trunk/matplotlib/CHANGELOG 2008-07-11 18:21:53 UTC (rev 5747) @@ -1,3 +1,6 @@ +2008-07-11 Fix memory leak related to shared axes. Grouper should + store weak references. - MGD + 2008-07-10 Bugfix: crash displaying fontconfig pattern - MGD 2008-07-10 Bugfix: [ 2013963 ] update_datalim_bounds in Axes not works - MGD Modified: trunk/matplotlib/lib/matplotlib/axes.py =================================================================== --- trunk/matplotlib/lib/matplotlib/axes.py 2008-07-11 16:30:07 UTC (rev 5746) +++ trunk/matplotlib/lib/matplotlib/axes.py 2008-07-11 18:21:53 UTC (rev 5747) @@ -904,6 +904,8 @@ self.xaxis.set_clip_path(self.patch) self.yaxis.set_clip_path(self.patch) + self._shared_x_axes.clear() + self._shared_y_axes.clear() def clear(self): 'clear the axes' Modified: trunk/matplotlib/lib/matplotlib/cbook.py =================================================================== --- trunk/matplotlib/lib/matplotlib/cbook.py 2008-07-11 16:30:07 UTC (rev 5746) +++ trunk/matplotlib/lib/matplotlib/cbook.py 2008-07-11 18:21:53 UTC (rev 5747) @@ -6,6 +6,7 @@ import re, os, errno, sys, StringIO, traceback, locale, threading import time, datetime import numpy as np +from weakref import ref major, minor1, minor2, s, tmp = sys.version_info @@ -1042,24 +1043,34 @@ def __init__(self, init=[]): mapping = self._mapping = {} for x in init: - mapping[x] = [x] + mapping[ref(x)] = [ref(x)] def __contains__(self, item): - return item in self._mapping + return ref(item) in self._mapping + def clean(self): + """ + Clean dead weak references from the dictionary + """ + mapping = self._mapping + for key, val in mapping.items(): + if key() is None: + del mapping[key] + val.remove(key) + def join(self, a, *args): """ Join given arguments into the same set. Accepts one or more arguments. """ mapping = self._mapping - set_a = mapping.setdefault(a, [a]) + set_a = mapping.setdefault(ref(a), [ref(a)]) for arg in args: - set_b = mapping.get(arg) + set_b = mapping.get(ref(arg)) if set_b is None: - set_a.append(arg) - mapping[arg] = set_a + set_a.append(ref(arg)) + mapping[ref(arg)] = set_a elif set_b is not set_a: if len(set_b) > len(set_a): set_a, set_b = set_b, set_a @@ -1067,13 +1078,17 @@ for elem in set_b: mapping[elem] = set_a + self.clean() + def joined(self, a, b): """ Returns True if *a* and *b* are members of the same set. """ + self.clean() + mapping = self._mapping try: - return mapping[a] is mapping[b] + return mapping[ref(a)] is mapping[ref(b)] except KeyError: return False @@ -1083,6 +1098,8 @@ The iterator is invalid if interleaved with calls to join(). """ + self.clean() + class Token: pass token = Token() @@ -1090,7 +1107,7 @@ # and don't yield it twice for group in self._mapping.itervalues(): if not group[-1] is token: - yield group + yield [x() for x in group] group.append(token) # Cleanup the tokens @@ -1102,9 +1119,12 @@ """ Returns all of the items joined with *a*, including itself. """ - return self._mapping.get(a, [a]) + self.clean() + siblings = self._mapping.get(ref(a), [ref(a)]) + return [x() for x in siblings] + def simple_linear_interpolation(a, steps): steps = np.floor(steps) new_length = ((len(a) - 1) * steps) + 1 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jd...@us...> - 2008-07-12 21:33:56
|
Revision: 5754 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5754&view=rev Author: jdh2358 Date: 2008-07-12 14:33:54 -0700 (Sat, 12 Jul 2008) Log Message: ----------- added support for external backends Modified Paths: -------------- trunk/matplotlib/CHANGELOG trunk/matplotlib/lib/matplotlib/__init__.py trunk/matplotlib/lib/matplotlib/backends/__init__.py trunk/matplotlib/lib/matplotlib/backends/backend_template.py trunk/matplotlib/matplotlibrc.template Modified: trunk/matplotlib/CHANGELOG =================================================================== --- trunk/matplotlib/CHANGELOG 2008-07-12 21:15:00 UTC (rev 5753) +++ trunk/matplotlib/CHANGELOG 2008-07-12 21:33:54 UTC (rev 5754) @@ -1,3 +1,6 @@ +2008-07-12 Added support for external backends with the + "module://my_backend" syntax - JDH + 2008-07-11 Fix memory leak related to shared axes. Grouper should store weak references. - MGD Modified: trunk/matplotlib/lib/matplotlib/__init__.py =================================================================== --- trunk/matplotlib/lib/matplotlib/__init__.py 2008-07-12 21:15:00 UTC (rev 5753) +++ trunk/matplotlib/lib/matplotlib/__init__.py 2008-07-12 21:33:54 UTC (rev 5754) @@ -801,8 +801,11 @@ if warn: warnings.warn(_use_error_msg) return arg = arg.lower() - be_parts = arg.split('.') - name = validate_backend(be_parts[0]) + if arg.startswith('module://'): + name = arg + else: + be_parts = arg.split('.') + name = validate_backend(be_parts[0]) rcParams['backend'] = name if name == 'cairo' and len(be_parts) > 1: rcParams['cairo.format'] = validate_cairo_format(be_parts[1]) Modified: trunk/matplotlib/lib/matplotlib/backends/__init__.py =================================================================== --- trunk/matplotlib/lib/matplotlib/backends/__init__.py 2008-07-12 21:15:00 UTC (rev 5753) +++ trunk/matplotlib/lib/matplotlib/backends/__init__.py 2008-07-12 21:33:54 UTC (rev 5754) @@ -1,10 +1,7 @@ import matplotlib -from matplotlib.rcsetup import interactive_bk -from matplotlib.rcsetup import non_interactive_bk -from matplotlib.rcsetup import all_backends -from matplotlib.rcsetup import validate_backend + __all__ = ['backend','show','draw_if_interactive', 'new_figure_manager', 'backend_version'] @@ -14,28 +11,24 @@ 'return new_figure_manager, draw_if_interactive and show for pylab' # Import the requested backend into a generic module object - backend_name = 'backend_'+backend - backend_name = backend_name.lower() # until we banish mixed case - backend_mod = __import__('matplotlib.backends.'+backend_name, + if backend.startswith('module://'): + backend_name = backend[9:] + else: + backend_name = 'backend_'+backend + backend_name = backend_name.lower() # until we banish mixed case + backend_name = 'matplotlib.backends.%s'%backend_name.lower() + backend_mod = __import__(backend_name, globals(),locals(),[backend_name]) # Things we pull in from all backends new_figure_manager = backend_mod.new_figure_manager - if hasattr(backend_mod,'backend_version'): - backend_version = getattr(backend_mod,'backend_version') - else: backend_version = 'unknown' + def do_nothing(*args, **kwargs): pass + backend_version = getattr(backend_mod,'backend_version', 'unknown') + show = getattr(backend_mod, 'show', do_nothing) + draw_if_interactive = getattr(backend_mod, 'draw_if_interactive', do_nothing) - - # Now define the public API according to the kind of backend in use - if backend in interactive_bk: - show = backend_mod.show - draw_if_interactive = backend_mod.draw_if_interactive - else: # non-interactive backends - def draw_if_interactive(): pass - def show(): pass - # Additional imports which only happen for certain backends. This section # should probably disappear once all backends are uniform. if backend.lower() in ['wx','wxagg']: Modified: trunk/matplotlib/lib/matplotlib/backends/backend_template.py =================================================================== --- trunk/matplotlib/lib/matplotlib/backends/backend_template.py 2008-07-12 21:15:00 UTC (rev 5753) +++ trunk/matplotlib/lib/matplotlib/backends/backend_template.py 2008-07-12 21:33:54 UTC (rev 5754) @@ -17,7 +17,7 @@ with 'xxx'. Then implement the class methods and functions below, and add 'xxx' to the switchyard in matplotlib/backends/__init__.py and 'xxx' to the backends list in the validate_backend methon in -matplotlib/__init__.py and you're off. You can use your backend with +matplotlib/__init__.py and you're off. You can use your backend with:: import matplotlib matplotlib.use('xxx') @@ -25,6 +25,17 @@ plot([1,2,3]) show() +matplotlib also supports external backends, so you can place you can +use any module in your PYTHONPATH with the syntax:: + + import matplotlib + matplotlib.use('module://my_backend') + +where my_backend.py is your module name. Thus syntax is also +recognized in the rc file and in the -d argument in pylab, eg:: + + python simple_plot.py -dmodule://my_backend + The files that are most relevant to backend_writers are matplotlib/backends/backend_your_backend.py Modified: trunk/matplotlib/matplotlibrc.template =================================================================== --- trunk/matplotlib/matplotlibrc.template 2008-07-12 21:15:00 UTC (rev 5753) +++ trunk/matplotlib/matplotlibrc.template 2008-07-12 21:33:54 UTC (rev 5754) @@ -19,8 +19,12 @@ # such as 0.75 - a legal html color name, eg red, blue, darkslategray #### CONFIGURATION BEGINS HERE + # the default backend; one of GTK GTKAgg GTKCairo CocoaAgg FltkAgg -# QtAgg Qt4Agg TkAgg WX WXAgg Agg Cairo GDK PS PDF SVG Template +# QtAgg Qt4Agg TkAgg WX WXAgg Agg Cairo GDK PS PDF SVG Template You +# can also deploy your own backend outside of matplotlib by referring +# to the module name (which must be in the PYTHONPATH) as +# 'module://my_backend' backend : %(backend)s numerix : %(numerix)s # numpy, Numeric or numarray #maskedarray : False # True to use external maskedarray module This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jd...@us...> - 2008-07-14 15:14:13
|
Revision: 5769 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5769&view=rev Author: jdh2358 Date: 2008-07-14 08:14:02 -0700 (Mon, 14 Jul 2008) Log Message: ----------- added support for pixels or data min coords to the rectangle selector widget Modified Paths: -------------- trunk/matplotlib/doc/faq/howto_faq.rst trunk/matplotlib/examples/widgets/rectangle_selector.py trunk/matplotlib/lib/matplotlib/artist.py trunk/matplotlib/lib/matplotlib/pyplot.py trunk/matplotlib/lib/matplotlib/widgets.py Modified: trunk/matplotlib/doc/faq/howto_faq.rst =================================================================== --- trunk/matplotlib/doc/faq/howto_faq.rst 2008-07-14 12:54:59 UTC (rev 5768) +++ trunk/matplotlib/doc/faq/howto_faq.rst 2008-07-14 15:14:02 UTC (rev 5769) @@ -6,6 +6,33 @@ .. contents:: + +.. _howto-findobj: + +How do I find all the objects in my figure of a certain type? +============================================================= + +Every matplotlib artist (see :ref:`artist-tutorial`) has a method +called :meth:`~matplotlib.artist.Artist.findobj` that can be used to +recursively search the artist for any artists it may contain that meet +some criteria (eg match all :class:`~matplotlib.lines.Line2D` +instances or match some arbitrary filter function). For example, the +following snippet finds every object in the figure which has a +`set_color` property and makes the object blue:: + + def myfunc(x): + return hasattr(x, 'set_color') + + for o in fig.findobj(myfunc): + o.set_color('blue') + +You can also filter on class instances:: + + import matplotlib.text as text + for o in fig.findobj(text.Text): + o.set_fontstyle('italic') + + .. _howto-transparent: How do I save transparent figures? Modified: trunk/matplotlib/examples/widgets/rectangle_selector.py =================================================================== --- trunk/matplotlib/examples/widgets/rectangle_selector.py 2008-07-14 12:54:59 UTC (rev 5768) +++ trunk/matplotlib/examples/widgets/rectangle_selector.py 2008-07-14 15:14:02 UTC (rev 5769) @@ -29,5 +29,6 @@ # drawtype is 'box' or 'line' or 'none' LS = RectangleSelector(current_ax, line_select_callback, - drawtype='box',useblit=True) + drawtype='box',useblit=True, + minspanx=5,minspany=5,spancoords='pixels') show() Modified: trunk/matplotlib/lib/matplotlib/artist.py =================================================================== --- trunk/matplotlib/lib/matplotlib/artist.py 2008-07-14 12:54:59 UTC (rev 5768) +++ trunk/matplotlib/lib/matplotlib/artist.py 2008-07-14 15:14:02 UTC (rev 5769) @@ -510,6 +510,9 @@ def findobj(self, match=None): """ + pyplot signature: + findobj(o=gcf(), match=None) + recursively find all :class:matplotlib.artist.Artist instances contained in self @@ -520,6 +523,8 @@ - function with signature ``boolean = match(artist)`` used to filter matches - class instance: eg Line2D. Only return artists of class type + + .. plot:: ../mpl_examples/pylab_examples/findobj_demo.py """ if match is None: # always return True Modified: trunk/matplotlib/lib/matplotlib/pyplot.py =================================================================== --- trunk/matplotlib/lib/matplotlib/pyplot.py 2008-07-14 12:54:59 UTC (rev 5768) +++ trunk/matplotlib/lib/matplotlib/pyplot.py 2008-07-14 15:14:02 UTC (rev 5769) @@ -7,7 +7,7 @@ from matplotlib.backend_bases import FigureCanvasBase from matplotlib.image import imread as _imread from matplotlib import rcParams, rcParamsDefault, get_backend -from matplotlib.artist import getp, get +from matplotlib.artist import getp, get, Artist from matplotlib.artist import setp as _setp from matplotlib.axes import Axes from matplotlib.projections import PolarAxes @@ -41,26 +41,11 @@ def findobj(o=None, match=None): - """ - recursively find all :class:matplotlib.artist.Artist instances - contained in artist instance *p*. if *o* is None, use - current figure - - *match* can be - - - None: return all objects contained in artist (including artist) - - - function with signature ``boolean = match(artist)`` used to filter matches - - - class instance: eg Line2D. Only return artists of class type - - """ - if o is None: o = gcf() return o.findobj(match) +findobj.__doc__ = Artist.findobj.__doc__ - def switch_backend(newbackend): """ Switch the default backend to newbackend. This feature is Modified: trunk/matplotlib/lib/matplotlib/widgets.py =================================================================== --- trunk/matplotlib/lib/matplotlib/widgets.py 2008-07-14 12:54:59 UTC (rev 5768) +++ trunk/matplotlib/lib/matplotlib/widgets.py 2008-07-14 15:14:02 UTC (rev 5769) @@ -979,7 +979,7 @@ """ Select a min/max range of the x axes for a matplotlib Axes - Example usage: + Example usage:: from matplotlib.widgets import RectangleSelector from pylab import * @@ -1011,7 +1011,7 @@ """ def __init__(self, ax, onselect, drawtype='box', minspanx=None, minspany=None, useblit=False, - lineprops=None, rectprops=None): + lineprops=None, rectprops=None, spancoords='data'): """ Create a selector in ax. When a selection is made, clear @@ -1035,7 +1035,12 @@ Use type if you want the mouse to draw a line, a box or nothing between click and actual position ny setting + drawtype = 'line', drawtype='box' or drawtype = 'none'. + + spancoords is one of 'data' or 'pixels'. If 'data', minspanx + and minspanx will be interpreted in the same coordinates as + the x and ya axis, if 'pixels', they are in pixels """ self.ax = ax self.visible = True @@ -1072,6 +1077,10 @@ self.useblit = useblit self.minspanx = minspanx self.minspany = minspany + + assert(spancoords in ('data', 'pixels')) + + self.spancoords = spancoords self.drawtype = drawtype # will save the data (position at mouseclick) self.eventpress = None @@ -1125,15 +1134,22 @@ self.canvas.draw() # release coordinates, button, ... self.eventrelease = event - xmin, ymin = self.eventpress.xdata, self.eventpress.ydata - xmax, ymax = self.eventrelease.xdata, self.eventrelease.ydata - # calculate dimensions of box or line get values in the right - # order + + if self.spancoords=='data': + xmin, ymin = self.eventpress.xdata, self.eventpress.ydata + xmax, ymax = self.eventrelease.xdata, self.eventrelease.ydata + # calculate dimensions of box or line get values in the right + # order + elif self.spancoords=='pixels': + xmin, ymin = self.eventpress.x, self.eventpress.y + xmax, ymax = self.eventrelease.x, self.eventrelease.y + else: + raise ValueError('spancoords must be "data" or "pixels"') + + if xmin>xmax: xmin, xmax = xmax, xmin if ymin>ymax: ymin, ymax = ymax, ymin - - spanx = xmax - xmin spany = ymax - ymin xproblems = self.minspanx is not None and spanx<self.minspanx This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |