patch: adding kwargs 'which' in axes.grid and 'g' toggles all tick grid lines

[bringing it back to list]

Hi Matt,
Nice patch. Sorry this is a newbie question... How do you run this patch?

Hi Krishna,

this patch is a diff against matplotlib-svn-trunk and you need a working copy
of this to incorporate the patch automatically (instead of changing the lines
by hand). The patch was generated using
svn diff <filename> > <name>.patch

You can apply this patch to your working copy of matplotlibs svn by calling

patch -i <name>.patch -p0
here e.g.:
patch -i axes_grid_for_major_and_minor_ticks.patch -p0

in the folder of your working copy or allpying it to a single file
here e.g.:
patch lib/matplotlib/ axes_grid_for_major_and_minor_ticks.patch

Kind regards,


On Monday 26 April 2010 18:08:15 Pribadi, Krishna wrote:

Krishna Adrianto Pribadi

Test Engineer

Desk (TTF): 256.480.4450

Cell: 412.401.1477

Harley-Davidson Motor Co.

Talladega Test Facility

Vehicle Test Stands (VTS)

-----Original Message-----
From: Matthias Michler [mailto:MatthiasMichler@…361…]
Sent: Friday, April 23, 2010 4:09 AM
Subject: [Matplotlib-users] patch: adding kwargs 'which' in axes.grid and
'g' toggles all tick grid lines

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

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
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,