I have coordinates inside a sphere and I want to plot the whole 3D sphere as scattered points, but alongside I would also like to plot a 2D disk.
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
sns.set(font_scale=1)
sns.set_style("whitegrid")
from matplotlib import rc
rc('text', usetex=True)
rc('font', family='serif')
from mpl_toolkits.mplot3d import Axes3D
fig, (ax1, ax3) = plt.subplots(1, 2, figsize=(900 / 106, 600 / 106), constrained_layout = False)
# 2D
radius = np.random.uniform(size=5000)
phi = np.random.uniform(size=5000) * 2 * np.pi
x = radius * np.cos(phi)
y = radius * np.sin(phi)
plot = ax1.scatter(x, y, s = 10, marker='.')
ax1.set_xlabel('$x$')
ax1.set_ylabel('$y$')
ax1.set_aspect('equal')
# 2D
radius = np.random.uniform(size=5000)
phi = np.random.uniform(size=5000) * 2 * np.pi
alfa = np.random.uniform(size=5000) * np.pi
x = radius * np.cos(phi) * np.sin(alfa)
y = radius * np.sin(phi) * np.sin(alfa)
z = radius * np.cos(alfa)
ax3 = Axes3D(fig)
plot = ax3.scatter(x, y, z, s = 1, marker='.')
ax3.set_xlabel('$x$')
ax3.set_ylabel('$y$')
ax3.set_zlabel('$z$')
#ax3.view_init(30, 240)
ax3.set_aspect('equal', 'box')
#fig.colorbar(plot, shrink = 0.9, ticks = np.linspace(0, 1, 6), ax = ax3)
fig.tight_layout()
Now the problem with this code above is that the output is not nearly as what I would expect (the 3D is plotted on top).
Any ideas how to do this properly?