plotly 3维曲面

import numpy as np
import plotly.graph_objs as go
import matplotlib.pyplot as plt


def f(x, y):
    z = np.power(x, 2) + np.power(y, 2)
    return z


def fig():
    a = np.linspace(start=0, stop=3, num=4, dtype=np.int32)
    b = np.linspace(start=0, stop=3, num=4, dtype=np.int32)
    print(a)
    print(b)
    x, y = np.meshgrid(a, b)
    print(x)
    print(y)
    mesh(x, y)

    z = f(x, y)
    print(z)

    fig = go.Figure(data=[go.Surface(x=x, y=y, z=z)])

    fig.update_layout(
        title_text='3D',
        height=800,
        width=800,
        autosize=False,
        margin=dict(l=65, r=50, b=65, t=90)
    )

    fig.show()


# 观察通过meshgrid形成的x-y坐标轴数据点。
def mesh(x, y):
    plt.xlabel('x axis')
    plt.ylabel('y axis')
    plt.plot(x, y, marker='^', color='red', linestyle='none')
    plt.grid()
    plt.show()


if __name__ == '__main__':
    fig()

生成的数据点:

[0 1 2 3]
[0 1 2 3]
[[0 1 2 3]
 [0 1 2 3]
 [0 1 2 3]
 [0 1 2 3]]
[[0 0 0 0]
 [1 1 1 1]
 [2 2 2 2]
 [3 3 3 3]]
[[ 0  1  4  9]
 [ 1  2  5 10]
 [ 4  5  8 13]
 [ 9 10 13 18]]

x-y坐标轴散点:

最终的3D(3维)曲面:

发布了1029 篇原创文章 · 获赞 987 · 访问量 336万+

猜你喜欢

转载自blog.csdn.net/zhangphil/article/details/103687805