利用Python实现三维散点图
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from pylab import *
mpl.rcParams['font.sans-serif'] = ['SimHei']
data = pd.read_excel(u'E:\附件一:已结束项目任务数据.xls',sheetname='t_tasklaunch')
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
# np.random.rand(n)产生1*n数组,元素大小0-1
fig = plt.figure()
ax = fig.add_subplot(111, 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)]:
xs = data["任务gps经度"]
ys = data["任务gps 纬度"]
zs = data["任务执行情况"]
ax.scatter(xs, ys, zs, c=c, marker=m)
ax.set_xlabel('任务gps经度')
ax.set_ylabel('任务gps纬度')
ax.set_zlabel('任务执行情况')
plt.show()
欢迎加群:620139909