8000 Add keymap (default: G) to toggle minor grid. by anntzer · Pull Request #6875 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Add keymap (default: G) to toggle minor grid. #6875

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 21, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add keymap (default: G) to toggle minor grid.
If either minor grid is on, turn both of them off.  Otherwise, turn all
major and minor grids on (it usually doesn't make sense to have the
minor grids only).

Also change the behavior of `keymap.grid` ("g") to synchronize the grid
state of both axes.  Otherwise, if starting from only grids in one
direction (`plt.plot(); plt.grid(axis="x")`), "g" switches between only
`x` grid and only `y` grid, which is unlikely to be the expected
behavior.
  • Loading branch information
anntzer committed Aug 1, 2016
commit e8de04c4a2385e088ab421cc0f1fc74acaea7285
3 changes: 2 additions & 1 deletion doc/users/navigation_toolbar.rst
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ Close all plots **shift** + **w**
Constrain pan/zoom to x axis hold **x** when panning/zooming with mouse
Constrain pan/zoom to y axis hold **y** when panning/zooming with mouse
Preserve aspect ratio hold **CONTROL** when panning/zooming with mouse
Toggle grid **g** when mouse is over an axes
Toggle major grid **g** when mouse is over an axes
Toggle major and minor grid **G** when mouse is over an axes
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you say "major and minor grids", but in the api_changes, you say that "G" will toggle minor grids.

Toggle x axis scale (log/linear) **L** or **k** when mouse is over an axes
Toggle y axis scale (log/linear) **l** when mouse is over an axes
================================== =================================================
Expand Down
21 changes: 18 additions & 3 deletions lib/matplotlib/backend_bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -2482,6 +2482,7 @@ def key_press_handler(event, canvas, toolbar=None):
save_keys = rcParams['keymap.save']
quit_keys = rcParams['keymap.quit']
grid_keys = rcParams['keymap.grid']
grid_minor_keys = rcParams['keymap.grid_minor']
toggle_yscale_keys = rcParams['keymap.yscale']
toggle_xscale_keys = rcParams['keymap.xscale']
all = rcParams['keymap.all_axes']
Expand Down Expand Up @@ -2525,13 +2526,28 @@ def key_press_handler(event, canvas, toolbar=None):

# these bindings require the mouse to be over an axes to trigger

ax = event.inaxes
# switching on/off a grid in current axes (default key 'g')
if event.key in grid_keys:
event.inaxes.grid()
# If either major grid is on, turn all major and minor grids off.
if any(tick.gridOn
for tick in ax.xaxis.majorTicks + ax.yaxis.majorTicks):
ax.grid(False, which="both")
# Otherwise, turn the major grids on.
else:
ax.grid(True)
canvas.draw()
if event.key in grid_minor_keys:
# If either minor grid is on, turn all minor grids off.
if any(tick.gridOn
for tick in ax.xaxis.minorTicks + ax.yaxis.minorTicks):
ax.grid(False, which="minor")
# Otherwise, turn all major and minor grids on.
else:
ax.grid(True, which="both")
canvas.draw()
# 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()
if scale == 'log':
ax.set_yscale('linear')
Expand All @@ -2541,7 +2557,6 @@ def key_press_handler(event, canvas, toolbar=None):
ax.figure.canvas.draw()
# 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()
if scalex == 'log':
ax.set_xscale('linear')
Expand Down
1 change: 1 addition & 0 deletions lib/matplotlib/rcsetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -1313,6 +1313,7 @@ def validate_animation_writer_path(p):
'keymap.quit': [['ctrl+w', 'cmd+w', 'q'], validate_stringlist],
'keymap.quit_all': [['W', 'cmd+W', 'Q'], validate_stringlist],
'keymap.grid': [['g'], validate_stringlist],
'keymap.grid_minor': [['G'], validate_stringlist],
'keymap.yscale': [['l'], validate_stringlist],
'keymap.xscale': [['k', 'L'], validate_stringlist],
'keymap.all_axes': [['a'], validate_stringlist],
Expand Down
1 change: 1 addition & 0 deletions matplotlibrc.template
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,7 @@ backend : $TEMPLATE_BACKEND
#keymap.save : s # saving current figure
#keymap.quit : ctrl+w, cmd+w # close the current figure
#keymap.grid : g # switching on/off a grid in current axes
#keymap.grid_minor : G # switching on/off a grid in current axes
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could use a little bit more distinguishing from keymap.grid.

#keymap.yscale : l # toggle scaling of y-axes ('log'/'linear')
#keymap.xscale : L, k # toggle scaling of x-axes ('log'/'linear')
#keymap.all_axes : a # enable all axes
Expand Down
0