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

编程入门 行业动态 更新时间:2024-10-28 13:13:22
本文介绍了如何仅使用pcolor/pcolormesh绘制网格线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

通过使用ax.axhline& ax.axvline我可以这样绘制网格网络显示:

By using ax.axhline & ax.axvline I can plot the grid network shows like this:

i4.tietuku/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绘制网格的轮廓

Here is my question

Can I use pcolor/pcolrmesh to just draw the outline of the grid

推荐答案

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

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

如果您真的想使用ax.pcolor或ax.pcolormesh,则可以将facecolor参数设置为'none',将edgecolor参数设置为'k':

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.

更多推荐

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

本文发布于:2023-07-18 00:51:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1139281.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:网格   pcolor   pcolormesh

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!