meshgrid contour contourf

meshgrid contour contourf

参考video: https://www.bilibili.com/video/BV1qW411A775/?spm_id_from=333.337.search-card.all.click&vd_source=d171c31a396363b8ea8c0e92a59cee6b

官方文档: https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.contourf.html#matplotlib.pyplot.contourf

meshgrid 网格

  • 将一行, 一列的数组扩充到2D平面
import numpy as np
import matplotlib.pyplot as plt

x = np.arange(0, 11, 1)
y = np.arange(0, 11, 1)

xx, yy = np.meshgrid(x, y)
print(f'xx: \n{xx}')
'''
xx: 
[[ 0  1  2  3  4  5  6  7  8  9 10]
 [ 0  1  2  3  4  5  6  7  8  9 10]
 [ 0  1  2  3  4  5  6  7  8  9 10]
 [ 0  1  2  3  4  5  6  7  8  9 10]
 [ 0  1  2  3  4  5  6  7  8  9 10]
 [ 0  1  2  3  4  5  6  7  8  9 10]
 [ 0  1  2  3  4  5  6  7  8  9 10]
 [ 0  1  2  3  4  5  6  7  8  9 10]
 [ 0  1  2  3  4  5  6  7  8  9 10]
 [ 0  1  2  3  4  5  6  7  8  9 10]
 [ 0  1  2  3  4  5  6  7  8  9 10]]
'''
print(f'yy: \n{yy}')
'''
yy: 
[[ 0  0  0  0  0  0  0  0  0  0  0]
 [ 1  1  1  1  1  1  1  1  1  1  1]
 [ 2  2  2  2  2  2  2  2  2  2  2]
 [ 3  3  3  3  3  3  3  3  3  3  3]
 [ 4  4  4  4  4  4  4  4  4  4  4]
 [ 5  5  5  5  5  5  5  5  5  5  5]
 [ 6  6  6  6  6  6  6  6  6  6  6]
 [ 7  7  7  7  7  7  7  7  7  7  7]
 [ 8  8  8  8  8  8  8  8  8  8  8]
 [ 9  9  9  9  9  9  9  9  9  9  9]
 [10 10 10 10 10 10 10 10 10 10 10]]
'''

在这里插入图片描述

contour, 轮廓, contourf, 等高线

zz = np.sin(xx) + np.cos(yy)
fig, ax = plt.subplots()
plt.contour(xx, yy, zz,)
plt.show()

在这里插入图片描述

fig, ax = plt.subplots()
plt.contour(xx, yy, zz, levels=3, cmap=plt.cm.rainbow) # levels 指定展示的高度, cmap 指定颜色
plt.show()

在这里插入图片描述

# 指定level, 
fig, ax = plt.subplots()
CS = plt.contour(xx, yy, zz, cmap=plt.cm.rainbow)

# 画出等高线上的高度的text, 
ax.clabel(CS, inline=True, fontsize=10)
'''
文档: 
https://matplotlib.org/stable/gallery/images_contours_and_fields/contour_demo.html#sphx-glr-gallery-images-contours-and-fields-contour-demo-py
'''

plt.show()

在这里插入图片描述

fig, ax = plt.subplots()
plt.contourf(xx, yy, zz)
plt.show()

在这里插入图片描述

  • 5
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值