Advertisement
TTpocToXaKep

4D Sphere (with functionality) (saving photo)

Feb 23rd, 2023
626
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.87 KB | None | 0 0
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3.  
  4.  
  5. def plot4d(data):
  6.     fig = plt.figure(figsize=(5, 5))
  7.     ax = fig.add_subplot(projection="3d")
  8.     ax.xaxis.pane.fill = False
  9.     ax.yaxis.pane.fill = False
  10.     ax.zaxis.pane.fill = False
  11.     mask = data > 0.01
  12.     idx = np.arange(int(np.prod(data.shape)))
  13.     x, y, z = np.unravel_index(idx, data.shape)
  14.     ax.scatter(x, y, z, c=data.flatten(), s=10.0 * mask, edgecolor="face", alpha=0.2, marker="o", cmap="magma", linewidth=0)
  15.     plt.tight_layout()
  16.     plt.savefig("4D.png", dpi=250)
  17.     plt.show() # WARNING! Big load on the processor and videocard.
  18.  
  19.  
  20. if __name__ == "__main__":
  21.     X = np.arange(-10, 10, 0.5)
  22.     Y = np.arange(-10, 10, 0.5)
  23.     Z = np.arange(-10, 10, 0.5)
  24.     X, Y, Z = np.meshgrid(X, Y, Z, indexing="ij")
  25.     density_matrix = np.sin(np.sqrt(X**2 + Y**2 + Z**2))
  26.     plot4d(density_matrix)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement