Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0f7b472

Browse files
committed
Reduce getattr calls and use axis_map dictionary
The value in `axis_map` is the axes object for that axis so we can use that directly to get the object instead of using `getattr`s by looping over the items of the dictionary. This also removes the need to have an `axis_converter` dictionary.
1 parent fc91e61 commit 0f7b472

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

lib/matplotlib/backends/qt_editor/figureoptions.py

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,11 @@ def convert_limits(lim, converter):
4040
return map(float, lim)
4141

4242
axis_map = axes._axis_map
43-
axis_converter = {
44-
axis: getattr(getattr(axes, f'{axis}axis'), 'converter')
45-
for axis in axis_map.keys()
46-
}
4743
axis_limits = {
48-
axis: tuple(convert_limits(
49-
getattr(axes, f'get_{axis}lim')(), axis_converter[axis]
44+
axname: tuple(convert_limits(
45+
getattr(axes, f'get_{axname}lim')(), axis.converter
5046
))
51-
for axis in axis_map.keys()
47+
for axname, axis in axis_map.items()
5248
}
5349
general = [
5450
('Title', axes.get_title()),
@@ -192,19 +188,18 @@ def apply_callback(data):
192188
axes.set_title(title)
193189
generate_legend = general.pop()
194190

195-
for i, axis in enumerate(axis_map.keys()):
196-
ax = getattr(axes, f"{axis}axis")
191+
for i, (axname, ax) in enumerate(axis_map.items()):
197192
axmin = general[4*i]
198193
axmax = general[4*i + 1]
199194
axlabel = general[4*i + 2]
200195
axscale = general[4*i + 3]
201-
if getattr(axes, f"get_{axis}scale")() != axscale:
202-
getattr(axes, f"set_{axis}scale")(axscale)
196+
if getattr(axes, f"get_{axname}scale")() != axscale:
197+
getattr(axes, f"set_{axname}scale")(axscale)
203198

204-
getattr(axes, f"set_{axis}lim")(axmin, axmax)
205-
getattr(axes, f"set_{axis}label")(axlabel)
206-
setattr(ax, 'converter', axis_converter[axis])
207-
getattr(ax, 'set_units')(axis_units[axis])
199+
getattr(axes, f"set_{axname}lim")(axmin, axmax)
200+
getattr(axes, f"set_{axname}label")(axlabel)
201+
setattr(ax, 'converter', ax.converter)
202+
getattr(ax, 'set_units')(axis_units[axname])
208203
ax._update_axisinfo()
209204

210205
# Set / Curves

0 commit comments

Comments
 (0)