Skip to content

Commit

Permalink
Simplify function to change axis
Browse files Browse the repository at this point in the history
Previous proposal was over-engineered with the idea of
possibly extending the number of scales the axis could scale to.
Since we're likely to just stick to linear and log, the
function is now easier to understand and maintain.
  • Loading branch information
GuiMacielPereira committed May 31, 2024
1 parent b9d8dbd commit 0f6fd37
Showing 1 changed file with 3 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@
("Log x/Lin y", ("log", "linear")),
]
)
# Options to quickly switch axes scales with key shortcuts
AXES_SCALE_DEFAULT_SWITCH = ["linear", "log"]
COLORBAR_SCALE_MENU_OPTS = OrderedDict([("Linear", Normalize), ("Log", LogNorm)])


Expand Down Expand Up @@ -148,7 +146,6 @@ def on_scroll(self, event):
event.canvas.draw()

def on_key_press(self, event):

ax = event.inaxes
if ax is None or isinstance(ax, Axes3D) or len(ax.get_images()) == 0 and len(ax.get_lines()) == 0:
return
Expand All @@ -164,10 +161,9 @@ def on_key_press(self, event):
self._quick_change_axes((ax.get_xscale(), next_yscale), ax)

def _get_next_axis_scale(self, current_scale):
available_scales = AXES_SCALE_DEFAULT_SWITCH
scale_index = available_scales.index(current_scale) if current_scale in available_scales else 0
next_scale = available_scales[(scale_index + 1) % len(available_scales)]
return next_scale
if current_scale == "linear":
return "log"
return "linear"

def on_mouse_button_press(self, event):
"""Respond to a MouseEvent where a button was pressed"""
Expand Down

0 comments on commit 0f6fd37

Please sign in to comment.