| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -272,7 +272,11 @@ def _make_layout_margins(ax, renderer, h_pad, w_pad): | |||
| 272 | 272 | invTransFig = fig.transFigure.inverted().transform_bbox | |
| 273 | 273 | pos = ax.get_position(original=True) | |
| 274 | 274 | tightbbox = ax.get_tightbbox(renderer=renderer) | |
| 275 | - bbox = invTransFig(tightbbox) | ||
| 275 | + if tightbbox is None: | ||
| 276 | + bbox = pos | ||
| 277 | + else: | ||
| 278 | + bbox = invTransFig(tightbbox) | ||
| 279 | + | ||
| 276 | 280 | # this can go wrong: | |
| 277 | 281 | if not (np.isfinite(bbox.width) and np.isfinite(bbox.height)): | |
| 278 | 282 | # just abort, this is likely a bad set of co-ordinates that | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -387,3 +387,16 @@ def test_colorbar_location(): | |||
| 387 | 387 | fig.colorbar(pcm, ax=axs[-2, 3:], shrink=0.5, location='top') | |
| 388 | 388 | fig.colorbar(pcm, ax=axs[0, 0], shrink=0.5, location='left') | |
| 389 | 389 | fig.colorbar(pcm, ax=axs[1:3, 2], shrink=0.5, location='right') | |
| 390 | + | ||
| 391 | + | ||
| 392 | + def test_hidden_axes(): | ||
| 393 | + # test that if we make an axes not visible that constrained_layout | ||
| 394 | + # still works. Note the axes still takes space in the layout | ||
| 395 | + # (as does a gridspec slot that is empty) | ||
| 396 | + fig, axs = plt.subplots(2, 2, constrained_layout=True) | ||
| 397 | + axs[0, 1].set_visible(False) | ||
| 398 | + fig.canvas.draw() | ||
| 399 | + extents1 = np.copy(axs[0, 0].get_position().extents) | ||
| 400 | + | ||
| 401 | + np.testing.assert_allclose(extents1, | ||
| 402 | + [0.045552, 0.548288, 0.47319, 0.982638], rtol=1e-5) | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments