Home > Net >  Plotting curves on 3d plot with common x-axis
Plotting curves on 3d plot with common x-axis

Time:01-31

I would like to plot two curves in 3d such that the x-axis is shared for two curves. One curve must lie on the X-Z plane while the second curve must be on the X-Y plane.

I have tried to accomplish the same using with the following code.

import numpy as np
import matplotlib.pyplot as plt

ax = plt.figure().add_subplot(projection='3d')

x = np.linspace(0, 1, 100)
y = abs(np.sin(x*2*np.pi))

ax.plot(x, y, 'b', zs=0, zdir='x', label='curve in (x, z)')
ax.plot(x, y, 'r', zs=0, zdir='z', label='curve in (x, y)')
# Make legend, set axes limits and labels
ax.legend()
ax.set_xlim(0, 1)
ax.set_ylim(0, 1)
ax.set_zlim(0, 1)
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
ax.view_init(elev=20., azim=-35)

plt.show()

I have shown what I have accomplihed with this code in the left panel of enter image description here

import numpy as np
import matplotlib.pyplot as plt

ax = plt.figure().add_subplot(projection='3d')

x = np.linspace(0, 1, 100)
y = abs(np.sin(x*2*np.pi))

ax.plot(x, y, 'b', zs=0, zdir='x', label='curve in (x, z)')
ax.plot(y, x, 'r', zs=0, zdir='z', label='curve in (x, y)')
ax.legend()
ax.set_xlim(0, 1)
ax.set_ylim(0, 1)
ax.set_zlim(0, 1)
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
ax.view_init(elev=20., azim=-35)

plt.show()
  •  Tags:  
  • Related