Check expected number of axes is drawn in expected layout Parameters ---------- axes : matplotlib Axes object, or its list-like axes_num : number expected number of axes. Unnecessary axes should be set to invisible. layout : tuple expected layout, (e
(axes, axes_num=None, layout=None, figsize=None)
| 281 | |
| 282 | |
| 283 | def _check_axes_shape(axes, axes_num=None, layout=None, figsize=None): |
| 284 | """ |
| 285 | Check expected number of axes is drawn in expected layout |
| 286 | |
| 287 | Parameters |
| 288 | ---------- |
| 289 | axes : matplotlib Axes object, or its list-like |
| 290 | axes_num : number |
| 291 | expected number of axes. Unnecessary axes should be set to |
| 292 | invisible. |
| 293 | layout : tuple |
| 294 | expected layout, (expected number of rows , columns) |
| 295 | figsize : tuple |
| 296 | expected figsize. default is matplotlib default |
| 297 | """ |
| 298 | from pandas.plotting._matplotlib.tools import flatten_axes |
| 299 | |
| 300 | if figsize is None: |
| 301 | figsize = (6.4, 4.8) |
| 302 | visible_axes = _flatten_visible(axes) |
| 303 | |
| 304 | if axes_num is not None: |
| 305 | assert len(visible_axes) == axes_num |
| 306 | for ax in visible_axes: |
| 307 | # check something drawn on visible axes |
| 308 | assert len(ax.get_children()) > 0 |
| 309 | |
| 310 | if layout is not None: |
| 311 | x_set = set() |
| 312 | y_set = set() |
| 313 | for ax in flatten_axes(axes): |
| 314 | # check axes coordinates to estimate layout |
| 315 | points = ax.get_position().get_points() |
| 316 | x_set.add(points[0][0]) |
| 317 | y_set.add(points[0][1]) |
| 318 | result = (len(y_set), len(x_set)) |
| 319 | assert result == layout |
| 320 | |
| 321 | tm.assert_numpy_array_equal( |
| 322 | visible_axes[0].figure.get_size_inches(), |
| 323 | np.array(figsize, dtype=np.float64), |
| 324 | ) |
| 325 | |
| 326 | |
| 327 | def _flatten_visible(axes: Axes | Sequence[Axes]) -> Sequence[Axes]: |