- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我使用 cartopy 创建了一个开放街道 map 图:
from __future__ import division
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import cartopy.io.img_tiles as cimgt
request = cimgt.OSM()
extent = [-89, -88, 41, 42]
ax = plt.axes(projection=request.crs)
ax.set_extent(extent)
ax.add_image(request, 8)
plt.show()
现在我还有一个经度和纬度点的列表。如何在街道 map 上叠加这些经度和纬度点的热图?
我尝试过使用 hist2d,但这不起作用。
lons = (-88 --89)*np.random.random(100)+-89
lats = (41 - 42)*np.random.random(100)+42
ax.hist2d(lons,lats)
plt.show()
但这行不通。
我猜我必须在绘图命令中的某个地方抛出一个转换参数?但我不确定如何去做。
谢谢!
最佳答案
您对坐标转换的需求是正确的。这是带有结果图的工作代码。
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import cartopy.io.img_tiles as cimgt
request = cimgt.OSM()
fig, ax = plt.subplots(figsize=(10,16),
subplot_kw=dict(projection=request.crs))
extent = [-89, -88, 41, 42] # (xmin, xmax, ymin, ymax)
ax.set_extent(extent)
ax.add_image(request, 8)
# generate (x, y) centering at (extent[0], extent[2])
x = extent[0] + np.random.randn(1000)
y = extent[2] + np.random.randn(1000)
# do coordinate conversion of (x,y)
xynps = ax.projection.transform_points(ccrs.Geodetic(), x, y)
# make a 2D histogram
h = ax.hist2d(xynps[:,0], xynps[:,1], bins=40, zorder=10, alpha=0.5)
#h: (counts, xedges, yedges, image)
cbar = plt.colorbar(h[3], ax=ax, shrink=0.45, format='%.1f') # h[3]: image
plt.show()
编辑 1
当使用plt.subplots()
创建ax
时,它定义了特定的投影。在本例中,投影由关键字 projection=request.crs
定义。要在 ax
上绘制某些内容,您必须使用其坐标系。
坐标转换是通过语句中的函数transform_points()
完成的
xynps=ax.projection.transform_points(ccrs.Geodetic(), x, y)
哪里
返回值xynps
是 map 坐标数组。它有 2 列 x 和 y,位于当前 ax
使用的适当坐标系中。
关于python - OpenStreetMap 背景上的 Cartopy 热图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50611018/
我画了两组重叠的轴,一组是另一组的放大版。我想在缩放轴的角和它在较大轴上代表的矩形的角之间画线。但是,我画的线稍微偏离了位置。我试图将其浓缩为一个简单的示例: import cartopy.crs a
我想知道给定纬度和经度,坐标是陆地还是海洋 根据https://gis.stackexchange.com/questions/235133/checking-if-a-geocoordinate-p
我已经看到了一些关于这个主题的其他问题,但是库已经发生了很大的变化,以至于这些问题的答案似乎不再适用。 栅格 used to include an example用于在 Cartopy GeoAxes
我正在为 xarray 进行一些开发。我试图安装 rasterio 但它似乎搞砸了我的 cartopy 安装。 我在我的 mac 上安装了 rasterio: brew install gdal pi
使用 basemap ,我曾经像这样添加我的自定义边界 shapefile: map = Basemap(..) map.readshapefile(file.shp, 'attribute', dr
所以,多年来我一直在 Python 2.7 中使用 Basemap,我正在转向 Python3.7 并且想转向 cartopy。我处理大量数据,其中我有投影信息,但我没有数据的纬度和经度网格。这就是我
我想要制作一个点的动画,该点沿着 map 上的一个位置到另一个位置的路径移动。 例如,我使用大地测量变换绘制了从纽约到新德里的路径。例如。取自文档 Adding data to the map plt
我想绘制来自全局多维数据集的数据,但仅限于国家/地区列表。因此,我根据国家/地区的“边界框”选择一个子立方体。 到目前为止一切顺利。我正在寻找一种简单的方法来掩盖立方体中不属于我的任何国家/地区的所有
如果我定义一组具有给定高度和宽度的(地理)轴,我如何确保绘图将填充这些轴? import matplotlib.pyplot as plt import cartopy.crs as ccrs ax
我有两个 shapefile。一个是点要素 shapefile,名为“point.shp”,另一个是名为“polygon.shp”的多边形 shapefile。我想使用 cartopy 添加到 map
我是 cartopy 的新手,仍在学习基本功能。 我试图绘制一个特定的区域,但是,当我请求 80oN 时,cartopy 扩展了这个区域并生成了一个高达大约 85oN 的 map 。有没有办法确保我只
我正在尝试在北太平洋投影上绘制 250 hPa 位势高度、1000 hPa 可降水量和 250 hPa 风速。当尝试使用倒刺时,我没有收到错误,但倒刺并没有实际显示在 map 上。我认为这可能与我的数
我想用 180 在图的底部绘制北半球的极地立体图,以便我可以强调太平洋地区。我正在使用来自 git 的最新 cartopy,并且可以制作极坐标立体图没有问题,但我无法弄清楚如何更改图底部的经度。我尝试
我正在使用 matplotlib 和 Cartopy 从二维网格数据集生成图像。以下链接中的示例如下所示: 驱动此图像创建并将出现问题的关键代码如下: dataset = Dataset('/path
我想使用 Cartopy 仅绘制一个区域(在我的例子中,北美和南美)。 我目前正在使用以下代码: import cartopy import cartopy.crs as ccrs import ma
我正在尝试使用 Cartopy 在北极立体 map 投影上创建等高线图。我使用 add_cycular_point() 尝试解决经度 0 和经度 35X 之间存在间隙的问题,并按照文档 (always
我正在尝试使用 Cartopy 和 Anaconda Python 绘制 map 点,但在转换时遇到了一些奇怪的失败。在我的简单示例中,我试图绘制 3 个点,但它们正在加倍。 import matpl
如何在 Cartopy 中绘制美国县边界? 绘制州和国家边界非常简单 ax.add_feature(cfeature.BORDERS.with_scale('50m')) ax.add_feature
我正在尝试在 OSM 图 block 之上过度绘制一些卫星图像数据。 我可以分别绘制它们,但似乎不能过度绘制,我认为这取决于投影。 我加载数据并获取投影信息 ds = gdal.Open(fname)
我正在尝试使用 cartopy 绘制北极的轮廓。我已经使用了 add_circlic_point ,这已经成功地填充了 pcolormesh 中本初子午线的间隙,但是轮廓没有成功交叉,而是绕地球一圈进
我是一名优秀的程序员,十分优秀!