How to plot the grid line only using pcolor/pcolormesh

无人久伴 提交于 2019-12-06 03:20:59

I would use ax.grid for this instead. To control the positions of the grid lines you could set the positions of the ticks, e.g.:

fig, ax = plt.subplots(1, 1)

ax.grid(True, which='minor', axis='both', linestyle='-', color='k')

ax.set_xticks(lon_grid, minor=True)
ax.set_yticks(lat_grid, minor=True)

ax.set_xlim(lon_grid[0], lon_grid[-1])
ax.set_ylim(lat_grid[0], lat_grid[-1])


If you really want to use ax.pcolor or ax.pcolormesh instead, you could set the facecolor parameter to 'none' and the edgecolor parameter to 'k':

fig, ax = plt.subplots(1, 1)

x, y = np.meshgrid(lon_grid, lat_grid)
c = np.ones_like(x)

ax.pcolor(x, y, c, facecolor='none', edgecolor='k')

ax.set_xlim(lon_grid[0], lon_grid[-1])
ax.set_ylim(lat_grid[0], lat_grid[-1])

This is a very questionable hack, though.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!