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

Skip to content

Commit f7ec3b1

Browse files
committed
Inline the with_rasterized contextmanager.
1 parent 73a82ee commit f7ec3b1

File tree

1 file changed

+9
-17
lines changed

1 file changed

+9
-17
lines changed

lib/matplotlib/artist.py

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import six
55

66
from collections import OrderedDict, namedtuple
7-
from contextlib import contextmanager
87
from functools import wraps
98
import inspect
109
import re
@@ -43,30 +42,23 @@ def allow_rasterization(draw):
4342
other setup function calls, such as starting and flushing a mixed-mode
4443
renderer.
4544
"""
46-
@contextmanager
47-
def with_rasterized(artist, renderer):
48-
49-
if artist.get_rasterized():
50-
renderer.start_rasterizing()
51-
52-
if artist.get_agg_filter() is not None:
53-
renderer.start_filter()
5445

46+
# the axes class has a second argument inframe for its draw method.
47+
@wraps(draw)
48+
def draw_wrapper(artist, renderer, *args, **kwargs):
5549
try:
56-
yield
50+
if artist.get_rasterized():
51+
renderer.start_rasterizing()
52+
if artist.get_agg_filter() is not None:
53+
renderer.start_filter()
54+
55+
return draw(artist, renderer, *args, **kwargs)
5756
finally:
5857
if artist.get_agg_filter() is not None:
5958
renderer.stop_filter(artist.get_agg_filter())
60-
6159
if artist.get_rasterized():
6260
renderer.stop_rasterizing()
6361

64-
# the axes class has a second argument inframe for its draw method.
65-
@wraps(draw)
66-
def draw_wrapper(artist, renderer, *args, **kwargs):
67-
with with_rasterized(artist, renderer):
68-
return draw(artist, renderer, *args, **kwargs)
69-
7062
draw_wrapper._supports_rasterization = True
7163
return draw_wrapper
7264

0 commit comments

Comments
 (0)