MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / test_tightbbox

Function test_tightbbox

lib/matplotlib/tests/test_figure.py:832–854  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

830
831
832def test_tightbbox():
833 fig, ax = plt.subplots()
834 ax.set_xlim(0, 1)
835 t = ax.text(1., 0.5, 'This dangles over end')
836 renderer = fig.canvas.get_renderer()
837 x1Nom0 = 8.9875 # inches
838 assert abs(t.get_tightbbox(renderer).x1 - x1Nom0 * fig.dpi) < 2
839 assert abs(ax.get_tightbbox(renderer).x1 - x1Nom0 * fig.dpi) < 2
840 assert abs(fig.get_tightbbox(renderer).x1 - x1Nom0) < 0.05
841 assert abs(fig.get_tightbbox(renderer).x0 - 0.679) < 0.05
842 # now exclude t from the tight bbox so now the bbox is quite a bit
843 # smaller
844 t.set_in_layout(False)
845 x1Nom = 7.333
846 assert abs(ax.get_tightbbox(renderer).x1 - x1Nom * fig.dpi) < 2
847 assert abs(fig.get_tightbbox(renderer).x1 - x1Nom) < 0.05
848
849 t.set_in_layout(True)
850 x1Nom = 7.333
851 assert abs(ax.get_tightbbox(renderer).x1 - x1Nom0 * fig.dpi) < 2
852 # test bbox_extra_artists method...
853 assert abs(ax.get_tightbbox(renderer, bbox_extra_artists=[]).x1
854 - x1Nom * fig.dpi) < 2
855
856
857def test_axes_removal():

Callers

nothing calls this directly

Calls 6

set_in_layoutMethod · 0.80
subplotsMethod · 0.45
set_xlimMethod · 0.45
textMethod · 0.45
get_rendererMethod · 0.45
get_tightbboxMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…