1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Plot 3D graph using Python

Discussão em 'Python' iniciado por Stack, Março 8, 2025.

  1. Stack

    Stack Membro Participativo

    I trying to plot a graph of a function f(x, y) = x**x*y, but I'm getting an error:

    import matplotlib.pyplot as plt
    import numpy as np
    from mpl_toolkits.mplot3d import Axes3D

    def f(x,y):
    return x**x*y

    x = np.arange(-4.0, 4.0, 0.1)
    y = np.arange(-4.0, 4.0, 0.1)
    z = f(x, y)
    X, Y, Z = np.meshgrid(x, y, z)

    fig = plt.figure()
    ax = Axes3D(fig)
    ax.plot_surface(X, Y, Z)
    plt.xlabel('x')
    plt.ylabel('y')
    plt.show()


    First error is:


    /usr/local/lib/python3.7/dist-packages/ipykernel_launcher.py:2: RuntimeWarning: invalid value encountered in power
    ​

    And the second is:


    ValueError: Argument Z must be 2-dimensional.
    ​

    Continue reading...

Compartilhe esta Página