In [4]:
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
# %matplotlib widget
In [5]:
amplitude = np.linspace(0, 1, 2)
time = np.linspace(0, 6*np.pi, 100)
time_grid, amplitude_grid = np.meshgrid(time, amplitude)
electric_X = time_grid
electric_Y = amplitude_grid*np.sin(time_grid)
electric_Z = np.zeros(time_grid.shape)
magnetic_X = time_grid
magnetic_Y = np.zeros(time_grid.shape)
magnetic_Z = amplitude_grid*np.sin(time_grid)
In [6]:
fig = plt.figure(figsize = (9, 9))
ax = plt.axes(projection='3d', box_aspect = (1, 1, 1))
# ax = plt.axes(projection='3d')
wave1 = ax.plot_surface(electric_X, electric_Y, electric_Z, color = 'red', alpha = 0.5, label = 'Electric Wave')
wave1._facecolors2d = wave1._facecolor3d
wave1._edgecolors2d = wave1._edgecolor3d
wave2 = ax.plot_surface(magnetic_X, magnetic_Y, magnetic_Z, color = 'green', alpha = 0.5, label = 'Magnetic Wave')
wave2._facecolors2d = wave2._facecolor3d
wave2._edgecolors2d = wave2._edgecolor3d
ax.get_proj = lambda: np.dot(Axes3D.get_proj(ax), np.diag([2, 0.5, 0.5, 1.5]))
ax.legend()
Out[6]:
In [ ]:
In [ ]:
In [ ]:
In [ ]: