利用位置与监测数据绘制曲面图

import requests

import json

import numpy as np

 

import matplotlib.pyplot as plt

from mpl_toolkits.mplot3d import Axes3D

from matplotlib import cm

import pandas as pd

import seaborn as sns

from scipy import interpolate

 

dataPointUrl = "http://123.150.130.42:8082/aqi/points"

dataLogUrl = "http://media.hhdata.cn:52074/query"

dbName ="tjiot"

insertPointCount = 32

 

dataPoints = []

dataPointDict ={}

datasets = []

lx=[]

ly=[]

lz=[]

x=None

y=None

z=None

minX=0

minY=0

maxX=0

maxY=0

dltX=0

dltY=0


 

#get point x,y,id

#get point value id , pm25

#convert points dataset ( x,y,pm25)

#get maxX , maxY , minX , minY , deltX , deltY

#insert values ( nX , nY , nZ)

#draw graph


 

#get point x,y,id

dataPoints = requests.get(dataPointUrl).json() 

for item in dataPoints:

    info ={

        'id':item['id'] ,

        'x':item['longitude'],

        'y':item['latitude'],

        'v':0

    }

    dataPointDict[item['id']] = info

#get point value id , pm25

sql = "select  mean(pm25) as val from T_Log group by time(1d) , dId fill(0) order by time desc limit 1 "

url = "{}?db={}&q={}".format( dataLogUrl, dbName , sql)

logDatas = requests.post(url).json()["results"][0]['series']

for pointData in logDatas:

    pId =int(pointData['tags']['dId'])

    value = pointData['values'][0][1] 

    if( pId in dataPointDict.keys()):

        dataPointDict[pId]['v'] = value

#convert points dataset ( x,y,pm25)

for k,v in dataPointDict.items():

    datasets.append(v)

    lx.append(float(v['x']))

    ly.append(float(v['y']))

    lz.append(float(v['v']))

#get maxX , maxY , minX , minY , deltX , deltY

x = np.array(lx)

y = np.array(ly)

z = np.array(lz) 

minX = x.min()

minY = y.min()

maxX = x.max()

maxY = y.max()

dltX = ( maxX - minX)/insertPointCount

dltY = ( maxY - minY)/insertPointCount

#insert values ( nX , nY , nZ)

f = interpolate.interp2d(x, y, z, kind='cubic')

xnew = np.arange(minX, maxX , dltX)

ynew = np.arange(minY, maxY , dltY)

znew = f(xnew, ynew)

minZ = znew.min();

if( minZ<0):

    znew = znew + abs(minZ)

#print(xnew , ynew, znew)

#draw graph

#修改x,y,z输入画图函数前的shape

xx1, yy1 = np.meshgrid(xnew, ynew)

newshape = (xx1.shape[0])*(xx1.shape[0])

y_input = xx1.reshape(newshape)

x_input = yy1.reshape(newshape)

z_input = znew.reshape(newshape)

 

print(x)

#画图

sns.set(style='white')

fig = plt.figure()

ax = fig.add_subplot(111, projection='3d')

ax.plot_trisurf(x_input,y_input,z_input,cmap=cm.coolwarm)

plt.show()



利用位置与监测数据绘制曲面图