python的meshgrid的用法及灰度图像的显示

编程入门 行业动态 更新时间:2024-10-09 10:22:02

python的meshgrid的用法及<a href=https://www.elefans.com/category/jswz/34/1769417.html style=灰度图像的显示"/>

python的meshgrid的用法及灰度图像的显示

背景:

meshgrid可以代替数组的双重遍历,下面展示meshgrid进行画图,主要是将三维平面z=sin((x^2-y^2)^2+x*y)投影到xy平面,用z值作为各点的值。

软件:

python3.5

代码:

import numpy as np
import matplotlib.pyplot as pltpoint = np.arange(-5,5,.1)
x,y = np.meshgrid(point,point)z = np.sin((x**2-y**2)**2 + x*y)plt.imshow(z,cmap = plt.cm.gray)    #灰度显示,越小越黑
plt.title("Image plot of $\sin((x^2 - y^2)^2 + x*y)$ for a grid of values")
plt.show()

结果:


更多推荐

python的meshgrid的用法及灰度图像的显示

本文发布于:2024-02-07 05:40:35,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1753706.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:灰度   图像   python   meshgrid

发布评论

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

>www.elefans.com

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