堆栈的二维图 [英] Stack of 2D plot

查看:28
本文介绍了堆栈的二维图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Python和Matplotlib将0≤t≤2 pi的堆叠2D sin(omega t)用不同的omega值绘制为3 pi图.任何提示将不胜感激.

I am trying to plot stacked 2D sin(omega t) for 0 <= t <= 2 pi with different omega values as a 3D plot using Python and Matplotlib. Any hint will be appreciated.

(类似这个)

推荐答案

这可以通过简单的 绘图命令:

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的好挑战:

What I've shown is a simple start, and adjusting the cosmetic aspects of the plot is probably a good challenge to learn/explore more of python/matplotlib:

这篇关于堆栈的二维图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆