如何将原点居中在 imshow() 图的中心

编程入门 行业动态 更新时间:2024-10-15 12:37:55
本文介绍了如何将原点居中在 imshow() 图的中心的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

作为一个长程序的一部分,该程序可以模拟通过孔径的衍射,因此我不禁尝试使所得的 plt.imshow()的原点位于图的中心,即我想改变轴.

As a part of a long program to simulate diffraction through an aperture, I'm fiddling around trying to get my resulting plt.imshow() to have its origin in the centre of the plot, i.e. I wish to change the axes.

相关代码部分为:

n=40 lam=0.0006 k=(2*np.pi)/lam z=float(input("Type screen distance, z in mm: ")) rho=float(input("Type rho in mm: ")) delta = 2/n intensity = np.zeros((n+1,n+1)) for i in range(n+1): x=-1+(i*delta) for j in range(n+1): y =-1+(j*delta) intensity[i,j] = (abs(square_2dsimpson_eval(-rho/2,rho/2,n)))**2 plt.imshow(intensity) plt.show()

生成下面的图.提前致谢.

generating the below plot. Thanks in advance.

推荐答案

为了将原点放置在图像绘图的中心,可以使用对称的 extent .

In order to position the origin at the center of the image plot, you can use a symmetric extent.

import numpy as np import matplotlib.pyplot as plt x = np.array([[1,2,1,4],[2,5,3,1],[0,1,2,2]]) plt.imshow(x, extent=[-x.shape[1]/2., x.shape[1]/2., -x.shape[0]/2., x.shape[0]/2. ]) plt.show()

更多推荐

如何将原点居中在 imshow() 图的中心

本文发布于:2023-11-30 03:05:02,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1648510.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:原点   如何将   中心   imshow

发布评论

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

>www.elefans.com

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