简体   繁体   English

绘制热数据(使用 pcolormesh 或类似的)在地图边缘(cartopy)失败

[英]Plotting heat data (with pcolormesh or similar) fails in the edges of map (cartopy)

I want to plot heat data on a map (Cartopy projection), but on the edges of the map, a frame of cells is created regardless of the size of the array.我想在地图上绘制热数据(Cartopy 投影),但在地图的边缘,无论数组大小如何,都会创建一帧单元格。 It was noticed, that the columns on the far left and far right have identical values.注意到,最左侧和最右侧的列具有相同的值。

Code:代码:

import cartopy.crs as ccrs
import matplotlib.pyplot as plt
import numpy as np

ax = plt.axes(projection=ccrs.PlateCarree())
ax.set_global()
ax.coastlines()

heat_data = np.random.rand(10, 10)
lat = np.linspace(-90, 90, heat_data.shape[1])
lon = np.linspace(-180, 180, heat_data.shape[0])
ax.pcolormesh(lon, lat, np.transpose(heat_data), alpha = 0.2)
plt.show()

Outcome No1: Result without transparency of the array (first and last columns have identical values)结果 No1:数组不透明的结果(第一列和最后一列具有相同的值)

Outcome No2: Result with transparent array结果二:透明数组的结果

Running the code you provided worked fine for me, producing a map with transparent pcolormesh.运行您提供的代码对我来说效果很好,可以生成带有透明 pcolormesh 的地图。 I believe this is the desired result?我相信这是想要的结果吗?

OP 代码和结果图

You also have a fencepost issues which may be causing the problem.您也有可能导致问题的围栏问题。 Note that while you have made a 10 x 10 grid of cells, you specify lon and lat in a 10 x 10 grid that includes the endpoints, mot the centers of the grid.请注意,虽然您制作了一个 10 x 10 的单元格网格,但您在一个 10 x 10 的网格中指定了 lon 和 lat,该网格包括端点,位于网格的中心。 This will confuse meshgrid.这会混淆meshgrid。 Could you try:你能不能试试:

lat = np.linspace(-90, 90, heat_data.shape[1] +1)
lon = np.linspace(-180, 180, heat_data.shape[0] +1)

ie setting the edges of the blocks in the desired places.即在所需位置设置块的边缘。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM