1import matplotlib.pyplot as plt
2import numpy as np
3import json
4
5from matplotlib import cm
6from matplotlib.ticker import LinearLocator
7
8# Load data
9with open("computed_tables.json", "r") as f:
10 data = json.load(f)
11
12fig, ax = plt.subplots(subplot_kw={"projection": "3d"})
13
14# Extract data
15X_values = data["depths"] # Depth in km
16Y_values = data["angles"] # Angle in degrees
17X, Y = np.meshgrid(range(len(Y_values)), range(len(X_values)))
18Z = np.array(data["p_table"])
19Z2 = np.array(data["s_table"])
20
21# Plot the first surface (P table)
22surf = ax.plot_surface(X, Y, Z, cmap=cm.viridis, linewidth=1, antialiased=True, label="P-Wave Table")
23
24# Plot the second surface (S table)
25surf2 = ax.plot_surface(X, Y, Z2, cmap=cm.magma, linewidth=1, antialiased=True, label="S-Wave Table")
26
27# Customize axes labels
28ax.set_xlabel("Depth (km)", fontsize=12, labelpad=10)
29ax.set_ylabel("Angle (°)", fontsize=12, labelpad=10)
30ax.set_zlabel("Value", fontsize=12, labelpad=10)
31
32# Customize Z-axis format
33ax.zaxis.set_major_locator(LinearLocator(10))
34ax.zaxis.set_major_formatter('{x:.02f}')
35
36# Add color bars
37cbar1 = fig.colorbar(surf, shrink=0.5, aspect=5, pad=0.1)
38cbar1.set_label("P-Wave Value", fontsize=10)
39
40cbar2 = fig.colorbar(surf2, shrink=0.5, aspect=5, pad=0.1)
41cbar2.set_label("S-Wave Value", fontsize=10)
42
43# Set title
44ax.set_title("3D Visualization of P-Table and S-Table", fontsize=14, pad=20)
45
46plt.show()