def get_subplot_grid(n):
    """Get a (h, w) arrangement for up to 9 subplots."""
    assert 0 <= n <= 9
    if n <= 3:
        return 1, n
    elif n <= 6:
        return 2, n - 3
    else:
        return 3, n - 6