def plot_surface(axis: pyplot.Axes.axes,
                 _fun: Callable[[float, float], float],
                 dim_range: Tuple[float, float],
                 colormap=None):
    _x = numpy.linspace(dim_range[0],
                        dim_range[1],
                        endpoint=True,
                        num=int(dim_range[1] - dim_range[0]))
    _y = numpy.linspace(dim_range[0],
                        dim_range[1],
                        endpoint=True,
                        num=int(dim_range[1] - dim_range[0]))
    _z = tuple(_fun(__x, __y) for __x, __y in zip(_x, _y))

    _X, _Y = numpy.meshgrid(_x, _y)
    _Z = _fun(_X, _Y)

    z_min, z_max = get_min_max(_z)
    z_margin = (z_max - z_min) * .1
    min_margin = z_min - z_margin
    max_margin = z_max + z_margin

    try:
        axis.set_zlim((min_margin, max_margin))
    except ValueError:
        print("infinite axis value")

    if colormap is None:
        return axis.plot_surface(_X, _Y, _Z, alpha=.2, antialiased=False)
    return axis.plot_surface(_X,
                             _Y,
                             _Z,
                             alpha=.2,
                             antialiased=False,
                             cmap=colormap)
Example #2
0
def plot_surface(ax: pyplot.Axes.axes, a: float, b: float, c: float,
                 size: int):
    x = numpy.linspace(0, size, endpoint=False, num=size)
    y = numpy.linspace(0, size, endpoint=False, num=size)

    _X, _Y = numpy.meshgrid(x, y)
    _Z = a + b * _Y + c * _X

    ax.plot_surface(_X, _Y, _Z, alpha=.2, antialiased=False)
Example #3
0
def plot_surface(axis: pyplot.Axes.axes,
                 _fun: Callable[[float, float], float],
                 dim_ranges: Tuple[Tuple[float, float], Tuple[float, float]],
                 colormap=None,
                 resize: bool = False):
    _x = numpy.linspace(dim_ranges[0][0],
                        dim_ranges[0][1],
                        endpoint=True,
                        num=100)
    _y = numpy.linspace(dim_ranges[1][0],
                        dim_ranges[1][1],
                        endpoint=True,
                        num=100)

    _X, _Y = numpy.meshgrid(_x, _y)

    _z = numpy.array(
        tuple(
            _fun(__x, __y)
            for __x, __y in zip(numpy.ravel(_X), numpy.ravel(_Y))))

    _Z = _z.reshape(_X.shape)

    if resize:
        z_min, z_max = get_min_max(_z)
        z_margin = (z_max - z_min) * .1
        min_margin = z_min - z_margin
        max_margin = z_max + z_margin

        try:
            axis.set_zlim((min_margin, max_margin))
        except ValueError:
            print("infinite axis value")

    if colormap is None:
        return axis.plot_surface(_X, _Y, _Z, alpha=.2, antialiased=False)
    return axis.plot_surface(_X,
                             _Y,
                             _Z,
                             alpha=.2,
                             antialiased=False,
                             cmap=colormap)