gpt4 book ai didi

python - 如何仅使用 pcolor/pcolormesh 绘制网格线

转载 作者:太空宇宙 更新时间:2023-11-03 15:04:31 29 4
gpt4 key购买 nike

通过使用 ax.axhlineax.axvline 我可以绘制网格网络显示如下:

http://i4.tietuku.com/e90652c9a56b5e61.png

代码转载于此:

 lon_grid  = np.linspace(113.5,115.49,36)
lat_grid = np.linspace(37.40,38.78,30)

lon_grid,lat_grid = np.linspace(xc1,xc2,36), np.linspace(yc1,yc2,30)
for i in range(0,len(lon_grid),1):
ax.axvline(x=lon_grid[i], linestyle='-', color='black', linewidth=0.75, zorder=3)
for i in range(0,len(lat_grid),1):
ax.axhline(y=lat_grid[i], linestyle='-', color='black', linewidth=0.75, zorder=3)

这是我的问题

我可以使用 pcolor/pcolrmesh 来绘制网格的轮廓吗

最佳答案

我会使用 ax.grid为此。要控制网格线的位置,您可以设置刻度线的位置,例如:

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])

enter image description here


如果您真的想要使用ax.pcolorax.pcolormesh,您可以设置facecolor 'none' 的参数和 'k'edgecolor 参数:

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])

enter image description here

不过,这是一个非常值得怀疑的 hack。

关于python - 如何仅使用 pcolor/pcolormesh 绘制网格线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34543908/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com