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

Function test_count_bitmaps

lib/matplotlib/tests/test_backend_svg.py:152–206  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

150
151
152def test_count_bitmaps():
153 def count_tag(fig, tag):
154 with BytesIO() as fd:
155 fig.savefig(fd, format='svg')
156 buf = fd.getvalue().decode()
157 return buf.count(f"<{tag}")
158
159 # No rasterized elements
160 fig1 = plt.figure()
161 ax1 = fig1.add_subplot(1, 1, 1)
162 ax1.set_axis_off()
163 for n in range(5):
164 ax1.plot([0, 20], [0, n], "b-", rasterized=False)
165 assert count_tag(fig1, "image") == 0
166 assert count_tag(fig1, "path") == 6 # axis patch plus lines
167
168 # rasterized can be merged
169 fig2 = plt.figure()
170 ax2 = fig2.add_subplot(1, 1, 1)
171 ax2.set_axis_off()
172 for n in range(5):
173 ax2.plot([0, 20], [0, n], "b-", rasterized=True)
174 assert count_tag(fig2, "image") == 1
175 assert count_tag(fig2, "path") == 1 # axis patch
176
177 # rasterized can't be merged without affecting draw order
178 fig3 = plt.figure()
179 ax3 = fig3.add_subplot(1, 1, 1)
180 ax3.set_axis_off()
181 for n in range(5):
182 ax3.plot([0, 20], [n, 0], "b-", rasterized=False)
183 ax3.plot([0, 20], [0, n], "b-", rasterized=True)
184 assert count_tag(fig3, "image") == 5
185 assert count_tag(fig3, "path") == 6
186
187 # rasterized whole axes
188 fig4 = plt.figure()
189 ax4 = fig4.add_subplot(1, 1, 1)
190 ax4.set_axis_off()
191 ax4.set_rasterized(True)
192 for n in range(5):
193 ax4.plot([0, 20], [n, 0], "b-", rasterized=False)
194 ax4.plot([0, 20], [0, n], "b-", rasterized=True)
195 assert count_tag(fig4, "image") == 1
196 assert count_tag(fig4, "path") == 1
197
198 # rasterized can be merged, but inhibited by suppressComposite
199 fig5 = plt.figure()
200 fig5.suppressComposite = True
201 ax5 = fig5.add_subplot(1, 1, 1)
202 ax5.set_axis_off()
203 for n in range(5):
204 ax5.plot([0, 20], [0, n], "b-", rasterized=True)
205 assert count_tag(fig5, "image") == 5
206 assert count_tag(fig5, "path") == 1 # axis patch
207
208
209# Use Computer Modern Sans Serif, not Helvetica (which has no \textwon).

Callers

nothing calls this directly

Calls 6

count_tagFunction · 0.85
figureMethod · 0.80
add_subplotMethod · 0.80
set_rasterizedMethod · 0.80
set_axis_offMethod · 0.45
plotMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…