Skip to content Skip to sidebar Skip to footer

Stack Of 2d Plot

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. (something

Solution 1:

This can be done with the simple 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 inrange(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()

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:

enter image description here

Post a Comment for "Stack Of 2d Plot"