Could you help me with adjusting the axis in the 3d plot? I can't change these three axix separately. I hope that the dots are in the center of the plot. Thanks!
'''
import numpy as np
from matplotlib import pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
def gen_2d_dome(n_layers=6):
#T = [1, 10, 20, 30, 40, 50, 60]
#R = [0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6]
T = [1] [(x 1)*10 for x in range(n_layers-1)]
TT = [1] [(x 1)*10 for x in range(n_layers-1)]
R = [0.0] [(x 1)*0.1 for x in range(n_layers-1)]
T = [int(np.ceil(x*0.6)) for x in T]
TT = [int(np.ceil(x*0.6)) for x in TT]
R = [x*20 for x in R]
def rtpairs(r, n, nn):
for i in range(len(r)):
for j in range(n[I]):
for k in range(nn[I]):
yield r[i]*1, j*(2 * np.pi / n[i]),k*(1 * np.pi / nn[I])
points, ppoints = [], []
for r, t, tt in rtpairs(R, T, TT):
x, y,z = r * np.sin(tt)*np.cos(t), r *np.sin(tt)*np.sin(t),r*np.cos(tt)
if y>=-0 and z>=0:
ppoints.append([r,t,tt])
points.append([x,y,z])
points = np.array([[x/12*255 255,y/12*255 255,z/12*255 255] for x, y,z in points])
return points
ax = fig.gca(projection='3d')
#ax.set_xlim3d(1,200)
ax.scatter(g[:, 0], g[:, 1], g[:, 2])
#ax.plot(g[:, 0], g[:, 1], g[:, 2])
plt.rcParams["figure.figsize"] = (10,6)
plt.show()
'''
CodePudding user response:
You can use ax.set_xlim
, ax.set_ylim
, ax.set_zlim
:
g = gen_2d_dome()
fig = plt.figure()
ax = fig.add_subplot(projection='3d')
ax.scatter(g[:, 0], g[:, 1], g[:, 2])
ax.set_xlim(g[:, 0].min(), g[:, 0].max())
ax.set_ylim(g[:, 1].min(), g[:, 1].max())
ax.set_zlim(g[:, 2].min(), g[:, 2].max())
plt.show()