简单python3D绘图---Axes3D

运行结果:
在这里插入图片描述

代码如下:

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

# 平面: x,y
# 3D: x,y,z
# f(x1,x2) = x1^2 - 3*x1*x2 + 4*x2^2

def func(X): # [1,2]
    return np.abs((X[0])**3)+np.abs(5*X[0]*X[1]) + np.abs(2*(X[1]+2)**3)
# meshgrid:

xs,ys= np.meshgrid(np.linspace(-50,50,101),np.linspace(-50,50,101))
print(xs)
print(ys)

# [xs[0][0],ys[0][0]]
# [xs[0][1],ys[0][1]]

zs = func([xs,ys])
print(zs)

# result = []
# for row1,row2 in zip(xs,ys):
#     row = []
#     for x1,x2 in zip(row1,row2):
#         row.append(func([x1,x2]))
#     result.append(row)
#
# print(np.array(result))

# 绘图

ax = plt.figure().add_subplot(111,projection='3d')
ax.plot_surface(xs,ys,zs)
xs = np.array([[10,20,30],
          [40,50,60],
          [17,20,19]])
ys = xs.T  # 矩阵转置
ax.scatter(xs,ys,func([xs,ys]),s=80,c='r')
plt.show()
  • 2
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值