Hello list, Hello developers, I'd like to summarize my discussion with Gökhan ("Turning off minor grids on log scaled plot") in the last days and propose two patches.
The first patch adds the keyword argument 'which' from the axis.grid to the method 'grid' of the Axes (axes_grid_for_major_and_minor_ticks.patch). This allows to change the drawing of grid lines for x- and y-axis at the same time. Furthemore Gökhan proposed to toggle *all* (namely major and minor tick) grid lines after pressing the key 'g'. Therefore the call event.inaxes.grid(), which toggles only the (default) major tick grid lines, is replaced by event.inaxes.grid(which='majorminor') (see toggling_all_tick_grid_lines.patch). This yields the expected behavior if e.g. all (major and minor) tick grid lines are shown, because than toggling the grid means to remove all grid lines. But to be honest I'm not sure the latter is the intended behavior in all cases. For instance in the case of shown major tick lines toggling all means turning off major tick lines and turning on minor tick lines by pressing 'g'. This sounds a little bit crazy to me, although that's what toggling is about. Thanks in advance for any comments. Kind regards, Matthias
Index: lib/matplotlib/axes.py =================================================================== --- lib/matplotlib/axes.py (revision 8267) +++ lib/matplotlib/axes.py (working copy) @@ -1932,19 +1932,20 @@ self._axisbelow = b @docstring.dedent_interpd - def grid(self, b=None, **kwargs): + def grid(self, b=None, which='major', **kwargs): """ call signature:: - grid(self, b=None, **kwargs) + grid(self, b=None, which='major', **kwargs) - Set the axes grids on or off; *b* is a boolean + Set the axes grids on or off; *b* is a boolean. Use *which* = + 'major' | 'minor' to set the grid for major or minor ticks. If *b* is *None* and ``len(kwargs)==0``, toggle the grid state. If *kwargs* are supplied, it is assumed that you want a grid and *b* is thus set to *True* - *kawrgs* are used to set the grid line properties, eg:: + *kwargs* are used to set the grid line properties, eg:: ax.grid(color='r', linestyle='-', linewidth=2) @@ -1953,8 +1954,8 @@ %(Line2D)s """ if len(kwargs): b = True - self.xaxis.grid(b, **kwargs) - self.yaxis.grid(b, **kwargs) + self.xaxis.grid(b, which=which, **kwargs) + self.yaxis.grid(b, which=which, **kwargs) def ticklabel_format(self, **kwargs): """
Index: lib/matplotlib/backend_bases.py =================================================================== --- lib/matplotlib/backend_bases.py (revision 8267) +++ lib/matplotlib/backend_bases.py (working copy) @@ -2109,9 +2109,9 @@ # the mouse has to be over an axes to trigger these # switching on/off a grid in current axes (default key 'g') if event.key in grid_keys: - event.inaxes.grid() + event.inaxes.grid(which="majorminor") self.canvas.draw() - # toggle scaling of y-axes between 'log and 'linear' (default key 'l') + # toggle scaling of y-axes between 'log' and 'linear' (default key 'l') elif event.key in toggle_yscale_keys: ax = event.inaxes scale = ax.get_yscale() @@ -2121,7 +2121,7 @@ elif scale == 'linear': ax.set_yscale('log') ax.figure.canvas.draw() - # toggle scaling of x-axes between 'log and 'linear' (default key 'k') + # toggle scaling of x-axes between 'log' and 'linear' (default key 'k') elif event.key in toggle_xscale_keys: ax = event.inaxes scalex = ax.get_xscale()
------------------------------------------------------------------------------
_______________________________________________ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users