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. 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)
Outcome No2: Result with transparent array
Running the code you provided worked fine for me, producing a map with transparent pcolormesh. I believe this is the desired result?
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. This will confuse 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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.