本文整理匯總了Python中matplotlib.backends.backend_agg.RendererAgg方法的典型用法代碼示例。如果您正苦於以下問題:Python backend_agg.RendererAgg方法的具體用法?Python backend_agg.RendererAgg怎麽用?Python backend_agg.RendererAgg使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類matplotlib.backends.backend_agg
的用法示例。
在下文中一共展示了backend_agg.RendererAgg方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: get_renderer
# 需要導入模塊: from matplotlib.backends import backend_agg [as 別名]
# 或者: from matplotlib.backends.backend_agg import RendererAgg [as 別名]
def get_renderer(self, cleared=False):
# Mirrors super.get_renderer, but caches the old one
# so that we can do things such as prodce a diff image
# in get_diff_image
_, _, w, h = self.figure.bbox.bounds
key = w, h, self.figure.dpi
try:
self._lastKey, self._renderer
except AttributeError:
need_new_renderer = True
else:
need_new_renderer = (self._lastKey != key)
if need_new_renderer:
self._renderer = backend_agg.RendererAgg(
w, h, self.figure.dpi)
self._last_renderer = backend_agg.RendererAgg(
w, h, self.figure.dpi)
self._lastKey = key
return self._renderer
示例2: get_renderer
# 需要導入模塊: from matplotlib.backends import backend_agg [as 別名]
# 或者: from matplotlib.backends.backend_agg import RendererAgg [as 別名]
def get_renderer(self, cleared=None):
# Mirrors super.get_renderer, but caches the old one
# so that we can do things such as produce a diff image
# in get_diff_image
_, _, w, h = self.figure.bbox.bounds
w, h = int(w), int(h)
key = w, h, self.figure.dpi
try:
self._lastKey, self._renderer
except AttributeError:
need_new_renderer = True
else:
need_new_renderer = (self._lastKey != key)
if need_new_renderer:
self._renderer = backend_agg.RendererAgg(
w, h, self.figure.dpi)
self._last_renderer = backend_agg.RendererAgg(
w, h, self.figure.dpi)
self._lastKey = key
elif cleared:
self._renderer.clear()
return self._renderer
示例3: get_renderer
# 需要導入模塊: from matplotlib.backends import backend_agg [as 別名]
# 或者: from matplotlib.backends.backend_agg import RendererAgg [as 別名]
def get_renderer(self, cleared=None):
# Mirrors super.get_renderer, but caches the old one
# so that we can do things such as produce a diff image
# in get_diff_image
_, _, w, h = self.figure.bbox.bounds
key = w, h, self.figure.dpi
try:
self._lastKey, self._renderer
except AttributeError:
need_new_renderer = True
else:
need_new_renderer = (self._lastKey != key)
if need_new_renderer:
self._renderer = backend_agg.RendererAgg(
w, h, self.figure.dpi)
self._last_renderer = backend_agg.RendererAgg(
w, h, self.figure.dpi)
self._lastKey = key
elif cleared:
self._renderer.clear()
return self._renderer
示例4: test_arrow_annotation_get_window_extent
# 需要導入模塊: from matplotlib.backends import backend_agg [as 別名]
# 或者: from matplotlib.backends.backend_agg import RendererAgg [as 別名]
def test_arrow_annotation_get_window_extent():
figure = Figure(dpi=100)
figure.set_figwidth(2.0)
figure.set_figheight(2.0)
renderer = RendererAgg(200, 200, 100)
# Text annotation with arrow
annotation = Annotation(
'', xy=(0.0, 50.0), xytext=(50.0, 50.0), xycoords='figure pixels',
arrowprops={
'facecolor': 'black', 'width': 8, 'headwidth': 10, 'shrink': 0.0})
annotation.set_figure(figure)
annotation.draw(renderer)
bbox = annotation.get_window_extent()
points = bbox.get_points()
eq_(bbox.width, 50.0)
assert_almost_equal(bbox.height, 10.0 / 0.72)
eq_(points[0, 0], 0.0)
eq_(points[0, 1], 50.0 - 5 / 0.72)
示例5: test_empty_annotation_get_window_extent
# 需要導入模塊: from matplotlib.backends import backend_agg [as 別名]
# 或者: from matplotlib.backends.backend_agg import RendererAgg [as 別名]
def test_empty_annotation_get_window_extent():
figure = Figure(dpi=100)
figure.set_figwidth(2.0)
figure.set_figheight(2.0)
renderer = RendererAgg(200, 200, 100)
# Text annotation with arrow
annotation = Annotation(
'', xy=(0.0, 50.0), xytext=(0.0, 50.0), xycoords='figure pixels')
annotation.set_figure(figure)
annotation.draw(renderer)
bbox = annotation.get_window_extent()
points = bbox.get_points()
eq_(points[0, 0], 0.0)
eq_(points[1, 0], 0.0)
eq_(points[1, 1], 50.0)
eq_(points[0, 1], 50.0)
示例6: draw
# 需要導入模塊: from matplotlib.backends import backend_agg [as 別名]
# 或者: from matplotlib.backends.backend_agg import RendererAgg [as 別名]
def draw(self):
# TODO: Do we just queue the drawing here? That's what Gtk does
renderer = self.get_renderer()
self._png_is_old = True
backend_agg.RendererAgg.lock.acquire()
try:
self.figure.draw(renderer)
finally:
backend_agg.RendererAgg.lock.release()
# Swap the frames
self.manager.refresh_all()
示例7: __getattr__
# 需要導入模塊: from matplotlib.backends import backend_agg [as 別名]
# 或者: from matplotlib.backends.backend_agg import RendererAgg [as 別名]
def __getattr__(self, attr):
# Proxy everything that hasn't been overridden to the base
# renderer. Things that *are* overridden can call methods
# on self._renderer directly, but must not cache/store
# methods (because things like RendererAgg change their
# methods on the fly in order to optimise proxying down
# to the underlying C implementation).
return getattr(self._renderer, attr)
示例8: draw
# 需要導入模塊: from matplotlib.backends import backend_agg [as 別名]
# 或者: from matplotlib.backends.backend_agg import RendererAgg [as 別名]
def draw(self):
renderer = self.get_renderer(cleared=True)
self._png_is_old = True
backend_agg.RendererAgg.lock.acquire()
try:
self.figure.draw(renderer)
finally:
backend_agg.RendererAgg.lock.release()
# Swap the frames
self.manager.refresh_all()
示例9: test_text_annotation_get_window_extent
# 需要導入模塊: from matplotlib.backends import backend_agg [as 別名]
# 或者: from matplotlib.backends.backend_agg import RendererAgg [as 別名]
def test_text_annotation_get_window_extent():
figure = Figure(dpi=100)
renderer = RendererAgg(200, 200, 100)
# Only text annotation
annotation = Annotation('test', xy=(0, 0))
annotation.set_figure(figure)
text = Text(text='test', x=0, y=0)
text.set_figure(figure)
bbox = annotation.get_window_extent(renderer=renderer)
text_bbox = text.get_window_extent(renderer=renderer)
eq_(bbox.width, text_bbox.width)
eq_(bbox.height, text_bbox.height)
_, _, d = renderer.get_text_width_height_descent(
'text', annotation._fontproperties, ismath=False)
_, _, lp_d = renderer.get_text_width_height_descent(
'lp', annotation._fontproperties, ismath=False)
below_line = max(d, lp_d)
# These numbers are specific to the current implementation of Text
points = bbox.get_points()
eq_(points[0, 0], 0.0)
eq_(points[1, 0], text_bbox.width)
eq_(points[0, 1], -below_line)
eq_(points[1, 1], text_bbox.height - below_line)
示例10: test_renderer
# 需要導入模塊: from matplotlib.backends import backend_agg [as 別名]
# 或者: from matplotlib.backends.backend_agg import RendererAgg [as 別名]
def test_renderer():
from matplotlib.backends.backend_agg import RendererAgg
renderer = RendererAgg(10, 20, 30)
pickle.dump(renderer, BytesIO())
示例11: __init__
# 需要導入模塊: from matplotlib.backends import backend_agg [as 別名]
# 或者: from matplotlib.backends.backend_agg import RendererAgg [as 別名]
def __init__(self, figure, width, height, dpi, vector_renderer,
raster_renderer_class=None,
bbox_inches_restore=None):
"""
Parameters
----------
figure : `matplotlib.figure.Figure`
The figure instance.
width : scalar
The width of the canvas in logical units
height : scalar
The height of the canvas in logical units
dpi : scalar
The dpi of the canvas
vector_renderer : `matplotlib.backend_bases.RendererBase`
An instance of a subclass of
`~matplotlib.backend_bases.RendererBase` that will be used for the
vector drawing.
raster_renderer_class : `matplotlib.backend_bases.RendererBase`
The renderer class to use for the raster drawing. If not provided,
this will use the Agg backend (which is currently the only viable
option anyway.)
"""
if raster_renderer_class is None:
raster_renderer_class = RendererAgg
self._raster_renderer_class = raster_renderer_class
self._width = width
self._height = height
self.dpi = dpi
self._vector_renderer = vector_renderer
self._raster_renderer = None
self._rasterizing = 0
# A reference to the figure is needed as we need to change
# the figure dpi before and after the rasterization. Although
# this looks ugly, I couldn't find a better solution. -JJL
self.figure = figure
self._figdpi = figure.get_dpi()
self._bbox_inches_restore = bbox_inches_restore
self._renderer = vector_renderer