python 3D绘图

from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
     
# 随机一百个数字数组     
def randrange(n, vmin, vmax):
        '''
        Helper function to make an array of random numbers having shape (n, )
        with each number distributed Uniform(vmin, vmax).
        '''
        return (vmax - vmin)*np.random.rand(n) + vmin
    
fig = plt.figure()
# add_subplot:绘图画布 111代表1行1列第一个 349代表3行4列第九个
ax = fig.add_subplot(111, projection='3d')
#     ax2 = fig.add_subplot(122, projection='3d')
     
n = 100
     
    # For each set of style and range settings, plot n random points in the box
    # defined by x in [23, 32], y in [0, 100], z in [zlow, zhigh].
for c, m, zlow, zhigh in [('r', 'o', -50, -25), ('b', '^', -30, -5),('g', '+', -20, -30)]:
    xs = randrange(n, 23, 32)
    print xs.shape
    ys = randrange(n, 0, 100)
    zs = randrange(n, zlow, zhigh)
    ax.scatter(xs, ys, zs, c=c, marker=m)

#设置坐标名    
ax.set_xlabel('X Label')
ax.set_ylabel('Y Label')
ax.set_zlabel('Z Label')

#设置轴范围
# ax.set_xlim(20, 32)
# ax.set_ylim(0, 100)
# ax.set_zlim(-50,0)

#设置轴具体数值
# ax.set_xticklabels([0,130,2])
# ax.set_yticklabels([0, 100])
# ax.set_xticklabels([-50,0])
plt.show()

猜你喜欢

转载自blog.csdn.net/a362682954/article/details/81702857
今日推荐