我尝试将一个单独轴上的网格覆盖在使用imread加载到matplotlib中的图像上。使用单独的轴的原因是为了显示网格线并使用不同的坐标系检测鼠标点击,而不是使用matplotlib在加载图像时创建的默认坐标系。将栅格轴的zorder更改为比图像轴更高的值,但图像将不可见。有没有其他方法?
ax1 = fig.add_subplot(111)
ax1.grid()
ax2 = ax1.twinx()
im = matplotlib.image.imread('pic.png')
ax2.imshow(im)
ax1.set_zorder(1) #grid is shown but image disappears
draw()发布于 2011-10-07 03:37:25
您可以使用set_alpha命令将网格的背景设置为透明,这与How to set opacity of background colour of graph wit Matplotlib上的问题答案类似
ax1 = fig.add_subplot(111)
ax1.grid()
ax1.patch.set_alpha(0)https://stackoverflow.com/questions/7678450
复制相似问题