From: <ef...@us...> - 2008-09-17 15:19:24
|
Revision: 6103 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6103&view=rev Author: efiring Date: 2008-09-17 22:19:20 +0000 (Wed, 17 Sep 2008) Log Message: ----------- colorbar docstring improvements: work in progress Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/colorbar.py Modified: trunk/matplotlib/lib/matplotlib/colorbar.py =================================================================== --- trunk/matplotlib/lib/matplotlib/colorbar.py 2008-09-17 20:53:16 UTC (rev 6102) +++ trunk/matplotlib/lib/matplotlib/colorbar.py 2008-09-17 22:19:20 UTC (rev 6103) @@ -13,9 +13,9 @@ a function for resizing an axes and adding a second axes suitable for a colorbar -The :meth:`matplotlib.Figure.colorbar` method uses :func:`make_axes` -and :class:`Colorbar`; the :func:`matplotlib.pyplot.colorbar` function -is a thin wrapper over :meth:`matplotlib.Figure.colorbar`. +The :meth:`~matplotlib.figure.Figure.colorbar` method uses :func:`make_axes` +and :class:`Colorbar`; the :func:`~matplotlib.pyplot.colorbar` function +is a thin wrapper over :meth:`~matplotlib.figure.Figure.colorbar`. ''' @@ -94,7 +94,7 @@ Function signatures for the :mod:`~matplotlib.pyplot` interface; all but the first are also method signatures for the -:meth:`matplotlib.Figure.colorbar` method:: +:meth:`~matplotlib.figure.Figure.colorbar` method:: colorbar(**kwargs) colorbar(mappable, **kwargs) @@ -104,9 +104,10 @@ arguments: *mappable* - the image, :class:`~matplotlib.contours.ContourSet`, etc. to + the :class:`matplotlib.image.Image`, + :class:`matplotlib.contour.ContourSet`, etc. to which the colorbar applies; this argument is mandatory for the - :meth:`matplotlib.Figure.colorbar` method but optional for the + :meth:`matplotlib.figure.Figure.colorbar` method but optional for the :func:`matplotlib.pyplot.colorbar` function, which sets the default to the current image. @@ -126,7 +127,7 @@ colorbar properties: %s -If mappable is a :class:`~matplotlib.contours.ContourSet`, its *extend* +If *mappable* is a :class:`~matplotlib.contours.ContourSet`, its *extend* kwarg is included automatically. Note that the *shrink* kwarg provides a simple way to keep a vertical @@ -138,6 +139,12 @@ For more precise control, you can manually specify the positions of the axes objects in which the mappable and the colorbar are drawn. In this case, do not use any of the axes properties kwargs. + +returns: + :class:`Colorbar` instance; see also its base class, + :class:`ColorbarBase`. Call the :meth:`set_label` method + to label the colorbar + ''' % (make_axes_kw_doc, colormap_kw_doc) @@ -162,6 +169,19 @@ norm=colors.NoNorm. + Useful attributes: + + :attr:`ax` + the Axes instance in which the colorbar is drawn + + :attr:`lines` + a LineCollection if lines were drawn, otherwise None + + :attr:`dividers` + a LineCollection if *drawedges* is True, otherwise None + + Useful public methods are :meth:`set_label` and :meth:`add_lines`. + ''' _slice_dict = {'neither': slice(0,1000000), 'both': slice(1,-1), @@ -196,6 +216,7 @@ self.filled = filled self.solids = None self.lines = None + self.dividers = None self.set_label('') if cbook.iterable(ticks): self.locator = ticker.FixedLocator(ticks, nbins=len(ticks)) @@ -272,6 +293,9 @@ self.ax.set_xlabel(self._label, **self._labelkw) def set_label(self, label, **kw): + ''' + Label the long axis of the colorbar + ''' self._label = label self._labelkw = kw self._set_label() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ef...@us...> - 2008-09-17 17:49:18
|
Revision: 6104 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6104&view=rev Author: efiring Date: 2008-09-18 00:49:15 +0000 (Thu, 18 Sep 2008) Log Message: ----------- More colorbar docstring improvements. Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/colorbar.py Modified: trunk/matplotlib/lib/matplotlib/colorbar.py =================================================================== --- trunk/matplotlib/lib/matplotlib/colorbar.py 2008-09-17 22:19:20 UTC (rev 6103) +++ trunk/matplotlib/lib/matplotlib/colorbar.py 2008-09-18 00:49:15 UTC (rev 6104) @@ -104,11 +104,11 @@ arguments: *mappable* - the :class:`matplotlib.image.Image`, - :class:`matplotlib.contour.ContourSet`, etc. to + the :class:`~matplotlib.image.Image`, + :class:`~matplotlib.contour.ContourSet`, etc. to which the colorbar applies; this argument is mandatory for the - :meth:`matplotlib.figure.Figure.colorbar` method but optional for the - :func:`matplotlib.pyplot.colorbar` function, which sets the + :meth:`~matplotlib.figure.Figure.colorbar` method but optional for the + :func:`~matplotlib.pyplot.colorbar` function, which sets the default to the current image. keyword arguments: @@ -141,9 +141,10 @@ this case, do not use any of the axes properties kwargs. returns: - :class:`Colorbar` instance; see also its base class, - :class:`ColorbarBase`. Call the :meth:`set_label` method - to label the colorbar + :class:`~matplotlib.colorbar.Colorbar` instance; see also its base class, + :class:`~matplotlib.colorbar.ColorbarBase`. Call the + :meth:`~matplotlib.colorbar.ColorbarBase.set_label` method + to label the colorbar. ''' % (make_axes_kw_doc, colormap_kw_doc) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ef...@us...> - 2008-12-15 06:23:33
|
Revision: 6606 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6606&view=rev Author: efiring Date: 2008-12-15 06:23:25 +0000 (Mon, 15 Dec 2008) Log Message: ----------- Add orientation kwarg to docstring Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/colorbar.py Modified: trunk/matplotlib/lib/matplotlib/colorbar.py =================================================================== --- trunk/matplotlib/lib/matplotlib/colorbar.py 2008-12-15 03:22:17 UTC (rev 6605) +++ trunk/matplotlib/lib/matplotlib/colorbar.py 2008-12-15 06:23:25 UTC (rev 6606) @@ -32,15 +32,16 @@ make_axes_kw_doc = ''' - ========== ==================================================== - Property Description - ========== ==================================================== - *fraction* 0.15; fraction of original axes to use for colorbar - *pad* 0.05 if vertical, 0.15 if horizontal; fraction - of original axes between colorbar and new image axes - *shrink* 1.0; fraction by which to shrink the colorbar - *aspect* 20; ratio of long to short dimensions - ========== ==================================================== + ============= ==================================================== + Property Description + ============= ==================================================== + *orientation* vertical or horizontal + *fraction* 0.15; fraction of original axes to use for colorbar + *pad* 0.05 if vertical, 0.15 if horizontal; fraction + of original axes between colorbar and new image axes + *shrink* 1.0; fraction by which to shrink the colorbar + *aspect* 20; ratio of long to short dimensions + ============= ==================================================== ''' This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lee...@us...> - 2009-06-19 04:33:45
|
Revision: 7226 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7226&view=rev Author: leejjoon Date: 2009-06-19 04:33:44 +0000 (Fri, 19 Jun 2009) Log Message: ----------- fix sf bug 2806283 (patch by Joonas Paalasmaa) Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/colorbar.py Modified: trunk/matplotlib/lib/matplotlib/colorbar.py =================================================================== --- trunk/matplotlib/lib/matplotlib/colorbar.py 2009-06-17 02:18:39 UTC (rev 7225) +++ trunk/matplotlib/lib/matplotlib/colorbar.py 2009-06-19 04:33:44 UTC (rev 7226) @@ -29,6 +29,7 @@ import matplotlib.patches as patches import matplotlib.collections as collections import matplotlib.contour as contour +import matplotlib.artist as martist make_axes_kw_doc = ''' @@ -626,9 +627,10 @@ self.mappable = mappable kw['cmap'] = mappable.cmap kw['norm'] = mappable.norm - kw['alpha'] = mappable.get_alpha() + if isinstance(mappable, contour.ContourSet): CS = mappable + kw['alpha'] = mappable.get_alpha() kw['boundaries'] = CS._levels kw['values'] = CS.cvalues kw['extend'] = CS.extend @@ -639,6 +641,9 @@ if not CS.filled: self.add_lines(CS) else: + if isinstance(mappable, martist.Artist): + kw['alpha'] = mappable.get_alpha() + ColorbarBase.__init__(self, ax, **kw) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lee...@us...> - 2010-02-06 23:52:40
|
Revision: 8114 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8114&view=rev Author: leejjoon Date: 2010-02-06 23:52:34 +0000 (Sat, 06 Feb 2010) Log Message: ----------- add Colorbar.set_ticks and Colorbar.set_ticklabels Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/colorbar.py Modified: trunk/matplotlib/lib/matplotlib/colorbar.py =================================================================== --- trunk/matplotlib/lib/matplotlib/colorbar.py 2010-02-06 23:44:28 UTC (rev 8113) +++ trunk/matplotlib/lib/matplotlib/colorbar.py 2010-02-06 23:52:34 UTC (rev 8114) @@ -18,6 +18,7 @@ is a thin wrapper over :meth:`~matplotlib.figure.Figure.colorbar`. ''' +import warnings import numpy as np import matplotlib as mpl @@ -207,6 +208,7 @@ filled=True, ): self.ax = ax + self._patch_ax() if cmap is None: cmap = cm.get_cmap() if norm is None: norm = colors.Normalize() self.alpha = alpha @@ -239,6 +241,13 @@ # The rest is in a method so we can recalculate when clim changes. self.draw_all() + def _patch_ax(self): + def _warn(*args, **kw): + warnings.warn("Use the colorbar set_ticks() method instead.") + + self.ax.set_xticks = _warn + self.ax.set_yticks = _warn + def draw_all(self): ''' Calculate any free parameters based on the current cmap and norm, @@ -253,6 +262,50 @@ self._add_solids(X, Y, C) self._set_label() + def update_ticks(self): + """ + Force the update of the ticks and ticklabels. This must be + called whenever the tick locator and/or tick formatter changes. + """ + ax = self.ax + ticks, ticklabels, offset_string = self._ticker() + if self.orientation == 'vertical': + ax.xaxis.set_ticks([]) + ax.yaxis.set_label_position('right') + ax.yaxis.set_ticks_position('right') + ax.yaxis.set_ticks(ticks) + ax.set_yticklabels(ticklabels) + ax.yaxis.get_major_formatter().set_offset_string(offset_string) + + else: + ax.yaxis.set_ticks([]) + ax.xaxis.set_label_position('bottom') + ax.xaxis.set_ticks(ticks) + ax.set_xticklabels(ticklabels) + ax.xaxis.get_major_formatter().set_offset_string(offset_string) + + def set_ticks(self, ticks, update_ticks=True): + """ + set tick locations. Tick locations are updated immediately unless update_ticks is + *False*. To manually update the ticks, call *update_ticks* method explicitly. + """ + self.locator = ticker.FixedLocator(ticks, nbins=len(ticks)) + if update_ticks: + self.update_ticks() + + def set_ticklabels(self, ticklabels, update_ticks=True): + """ + set tick labels. Tick labels are updated immediately unless update_ticks is + *False*. To manually update the ticks, call *update_ticks* method explicitly. + """ + if isinstance(self.locator, ticker.FixedLocator): + self.formatter = ticker.FixedFormatter(ticklabels) + if update_ticks: + self.update_ticks() + else: + warnings.warn("set_ticks() must have been called.") + + def _config_axes(self, X, Y): ''' Make an axes patch and outline. @@ -275,22 +328,10 @@ linewidth=0.01, zorder=-1) ax.add_artist(self.patch) - ticks, ticklabels, offset_string = self._ticker() - if self.orientation == 'vertical': - ax.set_xticks([]) - ax.yaxis.set_label_position('right') - ax.yaxis.set_ticks_position('right') - ax.set_yticks(ticks) - ax.set_yticklabels(ticklabels) - ax.yaxis.get_major_formatter().set_offset_string(offset_string) - else: - ax.set_yticks([]) - ax.xaxis.set_label_position('bottom') - ax.set_xticks(ticks) - ax.set_xticklabels(ticklabels) - ax.xaxis.get_major_formatter().set_offset_string(offset_string) + self.update_ticks() + def _set_label(self): if self.orientation == 'vertical': self.ax.set_ylabel(self._label, **self._labelkw) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ef...@us...> - 2010-04-28 20:49:54
|
Revision: 8286 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8286&view=rev Author: efiring Date: 2010-04-28 20:49:48 +0000 (Wed, 28 Apr 2010) Log Message: ----------- colorbar: close 2986719 with small fixups and docstring expansion Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/colorbar.py Modified: trunk/matplotlib/lib/matplotlib/colorbar.py =================================================================== --- trunk/matplotlib/lib/matplotlib/colorbar.py 2010-04-28 19:50:39 UTC (rev 8285) +++ trunk/matplotlib/lib/matplotlib/colorbar.py 2010-04-28 20:49:48 UTC (rev 8286) @@ -160,8 +160,9 @@ Draw a colorbar in an existing axes. This is a base class for the :class:`Colorbar` class, which is the - basis for the :func:`~matplotlib.pyplot.colorbar` method and pylab - function. + basis for the :func:`~matplotlib.pyplot.colorbar` function and the + :meth:`~matplotlib.figure.Figure.colorbar` method, which are the + usual ways of creating a colorbar. It is also useful by itself for showing a colormap. If the *cmap* kwarg is given but *boundaries* and *values* are left as None, @@ -411,6 +412,9 @@ if self.solids is not None: self.solids.remove() self.solids = col + if self.dividers is not None: + self.dividers.remove() + self.dividers = None if self.drawedges: self.dividers = collections.LineCollection(self._edges(X,Y), colors=(mpl.rcParams['axes.edgecolor'],), @@ -684,6 +688,17 @@ self.alpha = alpha class Colorbar(ColorbarBase): + """ + This class connects a :class:`ColorbarBase` to a + :class:`~matplotlib.cm.ScalarMappable` such as a + :class:`~matplotlib.image.AxesImage` generated via + :meth:`~matplotlib.axes.Axes.imshow`. + + It is not intended to be instantiated directly; instead, + use :meth:`~matplotlib.figure.Figure.colorbar` or + :func:`~matplotlib.pyplot.colorbar` to make your colorbar. + + """ def __init__(self, ax, mappable, **kw): mappable.autoscale_None() # Ensure mappable.norm.vmin, vmax # are set when colorbar is called, @@ -747,20 +762,28 @@ def update_bruteforce(self, mappable): ''' - Manually change any contour line colors. This is called - when the image or contour plot to which this colorbar belongs - is changed. + Destroy and rebuild the colorbar. This is + intended to become obsolete, and will probably be + deprecated and then removed. It is not called when + the pyplot.colorbar function or the Figure.colorbar + method are used to create the colorbar. + ''' # We are using an ugly brute-force method: clearing and # redrawing the whole thing. The problem is that if any # properties have been changed by methods other than the # colorbar methods, those changes will be lost. self.ax.cla() + # clearing the axes will delete outline, patch, solids, and lines: + self.outline = None + self.patch = None + self.solids = None + self.lines = None + self.set_alpha(mappable.get_alpha()) + self.cmap = mappable.cmap + self.norm = mappable.norm self.config_axis() self.draw_all() - #if self.vmin != self.norm.vmin or self.vmax != self.norm.vmax: - # self.ax.cla() - # self.draw_all() if isinstance(self.mappable, contour.ContourSet): CS = self.mappable if not CS.filled: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ef...@us...> - 2010-04-28 20:59:19
|
Revision: 8287 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8287&view=rev Author: efiring Date: 2010-04-28 20:59:13 +0000 (Wed, 28 Apr 2010) Log Message: ----------- colorbar: set dividers to None in obsolete update_bruteforce Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/colorbar.py Modified: trunk/matplotlib/lib/matplotlib/colorbar.py =================================================================== --- trunk/matplotlib/lib/matplotlib/colorbar.py 2010-04-28 20:49:48 UTC (rev 8286) +++ trunk/matplotlib/lib/matplotlib/colorbar.py 2010-04-28 20:59:13 UTC (rev 8287) @@ -779,6 +779,7 @@ self.patch = None self.solids = None self.lines = None + self.dividers = None self.set_alpha(mappable.get_alpha()) self.cmap = mappable.cmap self.norm = mappable.norm This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ry...@us...> - 2010-07-02 18:45:23
|
Revision: 8486 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8486&view=rev Author: ryanmay Date: 2010-07-02 18:45:17 +0000 (Fri, 02 Jul 2010) Log Message: ----------- Allow set_ticks to take a locator object, since this is valid for the ticks kwarg in __init__. Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/colorbar.py Modified: trunk/matplotlib/lib/matplotlib/colorbar.py =================================================================== --- trunk/matplotlib/lib/matplotlib/colorbar.py 2010-07-02 18:19:08 UTC (rev 8485) +++ trunk/matplotlib/lib/matplotlib/colorbar.py 2010-07-02 18:45:17 UTC (rev 8486) @@ -299,7 +299,11 @@ set tick locations. Tick locations are updated immediately unless update_ticks is *False*. To manually update the ticks, call *update_ticks* method explicitly. """ - self.locator = ticker.FixedLocator(ticks, nbins=len(ticks)) + if cbook.iterable(ticks): + self.locator = ticker.FixedLocator(ticks, nbins=len(ticks)) + else: + self.locator = ticks + if update_ticks: self.update_ticks() @@ -842,5 +846,3 @@ cax = fig.add_axes(pbcb) cax.set_aspect(aspect, anchor=anchor, adjustable='box') return cax, kw - - This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ef...@us...> - 2010-07-03 01:20:59
|
Revision: 8490 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8490&view=rev Author: efiring Date: 2010-07-03 01:20:53 +0000 (Sat, 03 Jul 2010) Log Message: ----------- colorbar: use pcolormesh instead of pcolor, to reduce artifacts Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/colorbar.py Modified: trunk/matplotlib/lib/matplotlib/colorbar.py =================================================================== --- trunk/matplotlib/lib/matplotlib/colorbar.py 2010-07-02 23:03:44 UTC (rev 8489) +++ trunk/matplotlib/lib/matplotlib/colorbar.py 2010-07-03 01:20:53 UTC (rev 8490) @@ -397,19 +397,18 @@ Draw the colors using :meth:`~matplotlib.axes.Axes.pcolor`; optionally add separators. ''' - ## Change to pcolorfast after fixing bugs in some backends... if self.orientation == 'vertical': args = (X, Y, C) else: args = (np.transpose(Y), np.transpose(X), np.transpose(C)) kw = {'cmap':self.cmap, 'norm':self.norm, - 'shading':'flat', 'alpha':self.alpha} + 'alpha':self.alpha,} # Save, set, and restore hold state to keep pcolor from # clearing the axes. Ordinarily this will not be needed, # since the axes object should already have hold set. _hold = self.ax.ishold() self.ax.hold(True) - col = self.ax.pcolor(*args, **kw) + col = self.ax.pcolormesh(*args, **kw) self.ax.hold(_hold) #self.add_observer(col) # We should observe, not be observed... This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |