Jae-Joon Lee wrote:
On Mon, Jan 25, 2010 at 7:19 PM, Jae-Joon Lee <lee.j.j...@gmail.com> wrote:
Adding a "set_ticks" method seems reasonable.

A patch is attached.

It looks like exactly what I had in mind with respect to set_ticks. I wasn't thinking about set_ticklabels; my sense is that manually setting ticklabels tends to be tricky and error-prone, and should be discouraged. Maybe it should be permitted only when a FixedLocator is already in use.

It does some refactoring and introduces three new methods, set_ticks,
set_ticklabels and update_ticks,  on the colorbar class.
So, now one can do

 imshow(np.arange(100).reshape((10,10)))
 cb = colorbar()
 cb.set_ticks([0, 40, 80])

Issuing a warning when user try to call Axis.set_ticks (or others)
directly seems not straight forward as the axes can be created
externally (i.e., when *cax* is provided).

Attached patch against svn (without your patch) shows how this can be done for the Axes methods. I would be more difficult (but not impossible) for the Axis methods, because we need to use them. I think that handling the Axes methods *may* be worthwhile (marginal), but handling the Axis methods is more trouble than it is worth.

Eric


I'll wait for response for a few more days and will commit the change.
Regards,

-JJ

Index: lib/matplotlib/colorbar.py
===================================================================
--- lib/matplotlib/colorbar.py	(revision 8097)
+++ lib/matplotlib/colorbar.py	(working copy)
@@ -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,
@@ -277,17 +286,17 @@
         ax.add_artist(self.patch)
         ticks, ticklabels, offset_string = self._ticker()
         if self.orientation == 'vertical':
-            ax.set_xticks([])
+            ax.xaxis.set_ticks([])
             ax.yaxis.set_label_position('right')
             ax.yaxis.set_ticks_position('right')
-            ax.set_yticks(ticks)
+            ax.yaxis.set_ticks(ticks)
             ax.set_yticklabels(ticklabels)
             ax.yaxis.get_major_formatter().set_offset_string(offset_string)
 
         else:
-            ax.set_yticks([])
+            ax.yaxis.set_ticks([])
             ax.xaxis.set_label_position('bottom')
-            ax.set_xticks(ticks)
+            ax.xaxis.set_ticks(ticks)
             ax.set_xticklabels(ticklabels)
             ax.xaxis.get_major_formatter().set_offset_string(offset_string)
 
------------------------------------------------------------------------------
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
Choose flexible plans and management services without long-term contracts
Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com
_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel

Reply via email to