Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Add keymap (default: G) to toggle minor grid. #6875
Conversation
mdboom
added the
needs_review
label
Aug 1, 2016
afvincent
and 1 other
commented on an outdated diff
Aug 1, 2016
| @@ -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_both': [['G'], validate_stringlist], |
afvincent
Contributor
|
|
Actually, after some more thought, I think I'll prefer another behavior for |
|
How the grids cycle through (x,y): (off, off), (on, on), (on, off), (off, on) ? This could probably be generalized to 3d in a strait forward way. |
tacaswell
added this to the
2.1 (next point release)
milestone
Aug 1, 2016
|
They switch both (which comes from the behavior of |
|
Also... there are no minor grids/ticks in mplot3d (at this point, that is). On Mon, Aug 1, 2016 at 12:29 PM, Antony Lee notifications@github.com
|
|
Implemented @tacaswell's suggestion. I chose the order (none)->(x)->(xy)->(y), so that one can easily switch from both-on to both-off and vice versa by typing "g/G" twice, which I think may be more user friendly. |
tacaswell
and 1 other
commented on an outdated diff
Aug 2, 2016
| + # Exclude major grids not in a uniform state. | ||
| + and None not in [_get_uniform_gridstate(ax.xaxis.majorTicks), | ||
| + _get_uniform_gridstate(ax.yaxis.majorTicks)]): | ||
| + x_state = _get_uniform_gridstate(ax.xaxis.minorTicks) | ||
| + y_state = _get_uniform_gridstate(ax.yaxis.minorTicks) | ||
| + cycle = [(False, False), (True, False), (True, True), (False, True)] | ||
| + try: | ||
| + x_state, y_state = ( | ||
| + cycle[(cycle.index((x_state, y_state)) + 1) % len(cycle)]) | ||
| + except ValueError: | ||
| + # Exclude minor grids not in a uniform state. | ||
| + pass | ||
| + else: | ||
| + ax.grid(x_state, which="both", axis="x") | ||
| + ax.grid(y_state, which="both", axis="y") | ||
| + canvas.draw() |
|
|
|
LGTM modulo an entry in whats_new. |
|
Sorry I'm late to the party. I know it is a lot of work, but can you add a tool or modify |
|
@anntzer if you have any questions regarding how to do it i'm happy to help |
|
How can I test my (TBD) implementation in the new API? |
|
take a look at |
|
Done. What's the status of MEP22? It's certainly a nicer API than the huge switch-based dispatch in key_press_handler... |
|
MEP22 is already merged but not completed, we are waiting for MEP27 to land, to modify all the backends. PRs are welcome! |
|
@anntzer can you correct the PEP8 problems? |
|
done |
jenshnielsen
closed this
Aug 9, 2016
jenshnielsen
reopened this
Aug 9, 2016
jenshnielsen
added needs_review and removed needs_review
labels
Aug 9, 2016
|
Cycled to rerun with current master and fix travis pyparsing issue |
|
|
WeatherGod
commented on an outdated diff
Aug 9, 2016
| @@ -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 |
WeatherGod
Member
|
WeatherGod
and 1 other
commented on an outdated diff
Aug 9, 2016
| @@ -399,24 +399,74 @@ def trigger(self, sender, event, data=None): | ||
| a.set_navigate(i == n) | ||
| -class ToolGrid(ToolToggleBase): | ||
| - """Tool to toggle the grid of the figure""" | ||
| +class _ToolGridBase(ToolBase): | ||
| + """Common functionality between ToolGrid and ToolMinorGrid. |
WeatherGod
Member
|
WeatherGod
and 1 other
commented on an outdated diff
Aug 9, 2016
| + return False | ||
| + else: | ||
| + return None | ||
| + | ||
| + | ||
| +class ToolGrid(_ToolGridBase): | ||
| + """Tool to toggle the major grids of the figure""" | ||
| + | ||
| + description = 'Toogle major grids' | ||
| + default_keymap = rcParams['keymap.grid'] | ||
| + | ||
| + def _get_next_grid_states(self, ax): | ||
| + x_state, y_state = map(self._get_uniform_grid_state, | ||
| + [ax.xaxis.majorTicks, ax.yaxis.majorTicks]) | ||
| + cycle = self._cycle | ||
| + # Bail out if major grids are not in a uniform state. |
anntzer
Contributor
|
WeatherGod
commented on an outdated diff
Aug 9, 2016
|
Not totally sold on the naming because it is called "minor", but it impacts both minor and major. |
WeatherGod
commented on the diff
Aug 16, 2016
| + | ||
| + description = 'Toogle major and minor grids' | ||
| + default_keymap = rcParams['keymap.grid_minor'] | ||
| + | ||
| + def _get_next_grid_states(self, ax): | ||
| + if None in map(self._get_uniform_grid_state, | ||
| + [ax.xaxis.majorTicks, ax.yaxis.majorTicks]): | ||
| + # Bail out if major grids are not in a uniform state. | ||
| + raise ValueError | ||
| + x_state, y_state = map(self._get_uniform_grid_state, | ||
| + [ax.xaxis.minorTicks, ax.yaxis.minorTicks]) | ||
| + cycle = self._cycle | ||
| + # Bail out (via ValueError) if minor grids are not in a uniform state. | ||
| + x_state, y_state = ( | ||
| + cycle[(cycle.index((x_state, y_state)) + 1) % len(cycle)]) | ||
| + return x_state, y_state, "both" |
WeatherGod
Member
|
tacaswell
merged commit 22aa800
into matplotlib:master
Aug 21, 2016
tacaswell
removed the
needs_review
label
Aug 21, 2016
anntzer
deleted the
anntzer:keymap-grid-minor branch
Aug 21, 2016
|
Note to self (or whoever wants to take over, should be easy enough): this implementation does not switch off the minor grids when the major grids are turned off, when it should probably do so. |
|
Small PR? On Aug 25, 2016 7:18 PM, "Antony Lee" notifications@github.com wrote:
|
|
Let's see whether playing the waiting game will get someone else to volunteer :) |
|
@anntzer that is not a game I would bet on winning |
anntzer commentedAug 1, 2016
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 gridstate of both axes. Otherwise, if starting from only grids in one
direction (
plt.plot(); plt.grid(axis="x")), "g" switches between onlyxgrid and onlyygrid, which is unlikely to be the expectedbehavior.
See #6616.