堆栈的2D绘图

时间:2012-04-24 17:31:20

标签: python matplotlib

我试图使用Python和Matplotlib将具有不同欧米伽值的0< = t< = 2 pi的堆叠2D sin(ωt)绘制为3D图。任何提示将不胜感激。

(像这样的东西)

Something like this one

1 个答案:

答案 0 :(得分:5)

这可以通过简单的plot command

来完成
from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt
import numpy as np

NANGLES = 200

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
nvals = [0, 2, 4, 10, 20, 40, 100]
for iy in range(len(nvals)):
    n = nvals[iy]
    x = np.arange(NANGLES) / float(NANGLES)
    y = np.ones(NANGLES)*iy # set y position to same value, with regular step
    z = np.sin(n*x*np.pi)
    ax.plot(x, y, z)
ax.set_ylabel('n')
ax.set_yticklabels(nvals) # update y ticks (set at regular step) to your vals

plt.savefig('stackedplot.png')
plt.show()

我所展示的是一个简单的开始,调整情节的美化方面可能是学习/探索更多python / matplotlib的一个很好的挑战:

enter image description here

相关问题