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

Function test_noop_tight_bbox

lib/matplotlib/tests/test_bbox_tight.py:144–169  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

142
143
144def test_noop_tight_bbox():
145 from PIL import Image
146 x_size, y_size = (10, 7)
147 dpi = 100
148 # make the figure just the right size up front
149 fig = plt.figure(frameon=False, dpi=dpi, figsize=(x_size/dpi, y_size/dpi))
150 ax = fig.add_axes((0, 0, 1, 1))
151 ax.set_axis_off()
152 ax.xaxis.set_visible(False)
153 ax.yaxis.set_visible(False)
154
155 data = np.arange(x_size * y_size).reshape(y_size, x_size)
156 ax.imshow(data, rasterized=True)
157
158 # When a rasterized Artist is included, a mixed-mode renderer does
159 # additional bbox adjustment. It should also be a no-op, and not affect the
160 # next save.
161 fig.savefig(BytesIO(), bbox_inches='tight', pad_inches=0, format='pdf')
162
163 out = BytesIO()
164 fig.savefig(out, bbox_inches='tight', pad_inches=0)
165 out.seek(0)
166 im = np.asarray(Image.open(out))
167 assert (im[:, :, 3] == 255).all()
168 assert not (im[:, :, :3] == 255).all()
169 assert im.shape == (7, 10, 4)
170
171
172@image_comparison(['bbox_inches_fixed_aspect.png'], remove_text=True,

Callers

nothing calls this directly

Calls 7

figureMethod · 0.80
add_axesMethod · 0.80
imshowMethod · 0.80
set_axis_offMethod · 0.45
set_visibleMethod · 0.45
savefigMethod · 0.45
openMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…