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()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值