Skip to content

speedup figure rendering removal of .startswith() calls and use generato... #2289

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 4 additions & 4 deletions lib/matplotlib/artist.py
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,7 @@ def get_aliases(self):

"""
names = [name for name in dir(self.o) if
(name.startswith('set_') or name.startswith('get_'))
(name[:4] in ['set_', 'get_'])
and callable(getattr(self.o, name))]
aliases = {}
for name in names:
Expand Down Expand Up @@ -927,7 +927,7 @@ def get_valid_values(self, attr):
if docstring is None:
return 'unknown'

if docstring.startswith('alias for '):
if docstring[:10] == 'alias for ':
return None

match = self._get_valid_values_regex.search(docstring)
Expand All @@ -943,7 +943,7 @@ def _get_setters_and_targets(self):

setters = []
for name in dir(self.o):
if not name.startswith('set_'):
if name[:4] != 'set_':
continue
o = getattr(self.o, name)
if not callable(o):
Expand Down Expand Up @@ -975,7 +975,7 @@ def is_alias(self, o):
ds = o.__doc__
if ds is None:
return False
return ds.startswith('alias for ')
return ds[:10] == 'alias for '

def aliased_name(self, s):
"""
Expand Down
6 changes: 3 additions & 3 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ def get_legend_handles_labels(self, legend_handler_map=None):
labels = []
for handle in self._get_legend_handles(legend_handler_map):
label = handle.get_label()
if label and not label.startswith('_'):
if label and label[0] != '_':
handles.append(handle)
labels.append(label)

Expand Down Expand Up @@ -5264,7 +5264,7 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None,

patches = []

if histtype.startswith('bar'):
if histtype[:3] == 'bar':
# Save autoscale state for later restoration; turn autoscaling
# off so we can do it all a single time at the end, instead
# of having it done by bar or fill and then having to be redone.
Expand Down Expand Up @@ -5326,7 +5326,7 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None,
self.set_autoscaley_on(_saved_autoscaley)
self.autoscale_view()

elif histtype.startswith('step'):
elif histtype[:4] == 'step':
# these define the perimeter of the polygon
x = np.zeros(4 * len(bins) - 3, np.float)
y = np.zeros(4 * len(bins) - 3, np.float)
Expand Down
25 changes: 9 additions & 16 deletions lib/matplotlib/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -972,17 +972,12 @@ def draw(self, renderer):
self.patch.draw(renderer)

# a list of (zorder, func_to_call, list_of_args)
dsu = []
dsu = [(x.get_zorder(), x, x.draw, [renderer]) for x in self.patches ]

for a in self.patches:
dsu.append((a.get_zorder(), a, a.draw, [renderer]))

for a in self.lines:
dsu.append((a.get_zorder(), a, a.draw, [renderer]))

for a in self.artists:
dsu.append((a.get_zorder(), a, a.draw, [renderer]))
dsu.extend((x.get_zorder(), x, x.draw, [renderer]) for x in self.lines)

dsu.extend((x.get_zorder(), x, x.draw, [renderer]) for x in self.artists)

# override the renderer default if self.suppressComposite
# is not None
not_composite = renderer.option_image_nocomposite()
Expand Down Expand Up @@ -1018,19 +1013,17 @@ def draw_composite():
draw_composite, []))

# render the axes
for a in self.axes:
dsu.append((a.get_zorder(), a, a.draw, [renderer]))
dsu.extend((x.get_zorder(), x, x.draw, [renderer]) for x in self.axes)

# render the figure text
for a in self.texts:
dsu.append((a.get_zorder(), a, a.draw, [renderer]))
dsu.extend((x.get_zorder(), x, x.draw, [renderer]) for x in self.texts)

for a in self.legends:
dsu.append((a.get_zorder(), a, a.draw, [renderer]))
# render the figure legends
dsu.extend((x.get_zorder(), x, x.draw, [renderer]) for x in self.legends)

dsu = [row for row in dsu if not row[1].get_animated()]
dsu.sort(key=itemgetter(0))
for zorder, a, func, args in dsu:
for zorder, a, func, args in dsu: # this also needs to go away for speed
func(*args)

renderer.close_group('figure')
Expand Down