Dataframe 是否可以根据此代码创建热图
可以用热图覆盖吗?或者有没有一种方法可以使用cartopy或geopandas创建热图 可以找到数据Dataframe 是否可以根据此代码创建热图,dataframe,matplotlib,openstreetmap,cartopy,Dataframe,Matplotlib,Openstreetmap,Cartopy,可以用热图覆盖吗?或者有没有一种方法可以使用cartopy或geopandas创建热图 可以找到数据 data=pd.read\u csv('data gathered1.csv')) 数据 x=数据[‘经度’] y=数据[“纬度”] 将matplotlib.pyplot作为plt导入 将numpy作为np导入 将cartopy.crs作为CCR导入 将cartopy.io.img_瓷砖作为cimgt导入 输入io 从urllib.request导入urlopen,请求 从PIL导入图像 def
data=pd.read\u csv('data gathered1.csv'))
数据
x=数据[‘经度’]
y=数据[“纬度”]
将matplotlib.pyplot作为plt导入
将numpy作为np导入
将cartopy.crs作为CCR导入
将cartopy.io.img_瓷砖作为cimgt导入
输入io
从urllib.request导入urlopen,请求
从PIL导入图像
def image_spoof(self,tile):#此函数假装不是Python脚本
url=self._image_url(tile)#获取街道地图API的url
请求=请求(url)#启动请求
请求添加标题(“用户代理”,“Anaconda 3”)#向请求添加用户代理
fh=urlopen(请求)
im_data=io.BytesIO(fh.read())#获取图像
fh.close()#关闭url
img=Image.open(im#u数据)#使用PIL打开图像
img=img.convert(自身所需的_tile_form)#设置图像格式
返回img,self.tileextent(tile),“lower”#重新格式化为cartopy
cimgt.OSM.get_image=image_spoof#重新格式化街道地图欺骗的web请求
osm_img=cimgt.osm()#伪造、下载的街道地图
图=plt.图(figsize=(12,9))#打开matplotlib图
ax1=plt.轴(投影=osm_img.crs)#使用街道坐标参考系(crs)投影
地图中心点=[26.2271,-98.2087]#拉特/隆伊达尔戈
缩放=0.5#用于缩小中心点
范围=[中心点[1]-(缩放*2.0),中心点[1]+(缩放*2.0),中心点[0]-缩放,中心点[0]+缩放]
调整
缩放
ax1.设置范围(范围)#设置范围
ax1.scatter(x,y,transform=ccrs.PlateCarree())
scale=np.ceil(-np.sqrt(2)*np.log(np.divide(zoom,350.0))#基于zoom的尺度经验解
scale=(scale我觉得非常有用
data=pd.read_csv('Data gathered1.csv')
data
x=data['LONGITUDE']
y= data["LATITUDE"]
import matplotlib.pyplot as plt
import numpy as np
import cartopy.crs as ccrs
import cartopy.io.img_tiles as cimgt
import io
from urllib.request import urlopen, Request
from PIL import Image
def image_spoof(self, tile): # this function pretends not to be a Python script
url = self._image_url(tile) # get the url of the street map API
req = Request(url) # start request
req.add_header('User-agent','Anaconda 3') # add user agent to request
fh = urlopen(req)
im_data = io.BytesIO(fh.read()) # get image
fh.close() # close url
img = Image.open(im_data) # open image with PIL
img = img.convert(self.desired_tile_form) # set image format
return img, self.tileextent(tile), 'lower' # reformat for cartopy
cimgt.OSM.get_image = image_spoof # reformat web request for street map spoofing
osm_img = cimgt.OSM() # spoofed, downloaded street map
fig = plt.figure(figsize=(12,9)) # open matplotlib figure
ax1 = plt.axes(projection=osm_img.crs) # project using coordinate reference system (CRS) of street
mapcenter_pt = [26.2271, -98.2087] # lat/lon hidalgo
zoom = 0.5 # for zooming out of center point
extent = [center_pt[1]-(zoom*2.0),center_pt[1]+(zoom*2.0),center_pt[0]-zoom,center_pt[0]+zoom] #
adjust
to zoom
ax1.set_extent(extent) # set extents
ax1.scatter(x,y, transform=ccrs.PlateCarree())
scale = np.ceil(-np.sqrt(2)*np.log(np.divide(zoom,350.0))) # empirical solve for scale based on zoom
scale = (scale<20) and scale or 19 # scale cannot be larger than 19
ax1.add_image(osm_img, int(scale)) # add OSM with zoom specification
plt.show()