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)
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)
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)
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)