简体   繁体   English

如何在 3mpl_toolkits.mplot3d python 中更改 x、y、z 轴

[英]How to change x, y, z axis in 3mpl_toolkits.mplot3d python

Could you help me with adjusting the axis in the 3d plot?你能帮我调整 3d 图中的轴吗? I can't change these three axix separately.我不能单独更改这三个 axix。 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()

''' '''

You can use ax.set_xlim , ax.set_ylim , ax.set_zlim :您可以使用ax.set_xlimax.set_ylimax.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()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用mpl_toolkits.mplot3d在Python Numpy中使用vstack进行for循环的更快方法 - Faster way for a for loop with vstack in Python Numpy using mpl_toolkits.mplot3d 如何在mplot3d上绘制表面以获取(x,y,z)=(0,0,1),(0,0,2)之类的数据 - How can I plot surface on mplot3d for data like (x,y,z)=(0,0,1),(0,0,2) 将颜色映射应用于mpl_toolkits.mplot3d.Axes3D.bar3d - apply color map to mpl_toolkits.mplot3d.Axes3D.bar3d Python/matplotlib mplot3d-如何设置 z 轴的最大值? - Python/matplotlib mplot3d- how do I set a maximum value for the z-axis? mplot3d中的z轴格式 - z-axis formatting in mplot3d 使用 Plotlyexpress 在 Scatter 3D 图中更改 (0,0,0) 处的 X、Y 和 Z 轴 - Change X,Y and Z axis at (0,0,0) in Scatter 3D plot using Plotlyexpress 如何在PyCharm中解析对依赖项'mpl_toolkits'的未知Python引用? - How to resolve unknown Python reference to dependency 'mpl_toolkits' in PyCharm? 更改 mpl_toolkits new_fixed_axis 中的轴线范围 - Change axis line range in mpl_toolkits new_fixed_axis 如何绘制2d平面,x轴范围从0到1,y轴范围从0到1,z轴0 - how can I plot a 2d plane x axis range from 0 to 1, y axis range from 0 to 1, and z axis 0 Python-如何在表面离散3D点(x,y,z)之后从给定的x,y获取z值 - Python - How to get z value from given x, y after surface discrete 3D points (x,y,z)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM