python三维图形旋转_如何在matplotlib中绘制三维旋转图?

你的图形上的图形似乎使用了笛卡尔网格。在matplotlib网站上有一些三维圆柱函数的例子,比如Z=f(R)(这里:http://matplotlib.org/examples/mplot3d/surface3d_radial_demo.html)。

这就是你要找的吗?

下面是您的函数Z=-R**2:

要在函数中添加截止值,请使用以下示例:

(需要matplotlib 1.2.0)from mpl_toolkits.mplot3d import Axes3D

from matplotlib import cm

import matplotlib.pyplot as plt

import numpy as np

fig = plt.figure()

ax = fig.gca(projection='3d')

X = np.arange(-5, 5, 0.25)

Y = np.arange(-5, 5, 0.25)

X, Y = np.meshgrid(X, Y)

Z = -(abs(X) + abs(Y))

## 1) Initial surface

# Flatten mesh arrays, necessary for plot_trisurf function

X = X.flatten()

Y = Y.flatten()

Z = Z.flatten()

# Plot initial 3D surface with triangles (more flexible than quad)

#surfi = ax.plot_trisurf(X, Y, Z, cmap=cm.jet, linewidth=0.2)

## 2) Cut off

# Get desired values indexes

cut_idx = np.where(Z > -5)

# Apply the "cut off"

Xc = X[cut_idx]

Yc = Y[cut_idx]

Zc = Z[cut_idx]

# Plot the new surface (it would be impossible with quad grid)

surfc = ax.plot_trisurf(Xc, Yc, Zc, cmap=cm.jet, linewidth=0.2)

# You can force limit if you want to compare both graphs...

ax.set_xlim(-5,5)

ax.set_ylim(-5,5)

ax.set_zlim(-10,0)

plt.show()

冲浪成绩:

和surfc:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值