6.2 数组和区域绘图

6.2.1 imshow(Z)

import matplotlib.pyplot as plt
import numpy as np

#make data
X,Y=np.meshgrid(np.linspace(-3,3,16),np.linspace(-3,3,16))
Z=(1-X/2+X**5+Y**3)*np.exp(-X**2-Y**2)

#plot
fig=plt.figure()
ax=plt.subplot()

ax.imshow(Z)
plt.show()

在这里插入图片描述

6.2.2 pcolormesh(X,Y,U,V)


import matplotlib.pyplot as plt
import numpy as np

#make data with uneven sampling in x
x=[-3,-2,-1.6,-1.2,-.8,-.5,-.2,.1,.3,.5,.8]
X,Y=np.meshgrid(x,np.linspace(-3,3,128))
Z=(1-X/2+X**5+Y**3)*np.exp(-X**2-Y**2)

#plot
fig=plt.figure()
ax=plt.subplot()

ax.pcolormesh(X,Y,Z,vmin=-0.5,vmax=1.0)
plt.show()

在这里插入图片描述

6.2.3 contour(X,Y,Z)

import matplotlib.pyplot as plt
import numpy as np

#make data
X,Y=np.meshgrid(np.linspace(-3,3,256),np.linspace(-3,3,256))
Z=(1-X/2+X**5+Y**3)*np.exp(-X**2-Y**2)
levels=np.linspace(np.min(Z),np.max(Z),7)

#plot
fig=plt.figure()
ax=plt.subplot()

ax.contour(X,Y,Z,levels=levels)
plt.show()

在这里插入图片描述

6.2.4 contourf(X,Y,Z)

import matplotlib.pyplot as plt
import numpy as np

#make data
X,Y=np.meshgrid(np.linspace(-3,3,256),np.linspace(-3,3,256))
Z=(1-X/2+X**5+Y**3)*np.exp(-X**2-Y**2)
levels=np.linspace(Z.min(),Z.max(),7)

#plot
fig=plt.figure()
ax=plt.subplot()

ax.contourf(X,Y,Z,levels=levels)

plt.show()

在这里插入图片描述

6.2.5 barbs(X,Y,U,V)

import matplotlib.pyplot as plt
import numpy as np

#make data
X,Y=np.meshgrid(np.linspace(-3,3,256),np.linspace(-3,3,256))
Z=(1-X/2+X**5+Y**3)*np.exp(-X**2-Y**2)
levels=np.linspace(Z.min(),Z.max(),7)

#plot
fig=plt.figure()
ax=plt.subplot()

ax.contourf(X,Y,Z,levels=levels)

plt.show()

在这里插入图片描述

6.2.6 quiver(X,Y,U,V)

import matplotlib.pyplot as plt
import numpy as np

#make data
X,Y=np.meshgrid([1,2,3],[1,2,3,4])
angle=np.pi/180*np.array([[10,20,30,60],
[25,40,55,60],
[35,50,65,75]])
amplitude=np.array([[5,10,25,50],
[10,15,30,60],
[15,26,50,70]])

U=amplitude*np.sin(angle)
V=amplitude*np.cos(angle)

#plot
fig=plt.figure()
ax=plt.subplot()

ax.barbs(X,Y,U,V,barbcolor="C0",flagcolor="C0",length=7,linewidth=1.5)

plt.show()

在这里插入图片描述

6.2.7 streamplot(X,Y,U,V)

import matplotlib.pyplot as plt
import numpy as np

#make data
x=np.linspace(-4,4,6)
y=np.linspace(-4,4,6)
X,Y=np.meshgrid(x,y)
U=X+Y
V=X-Y

#plot
fig=plt.figure()
ax=plt.subplot()

ax.quiver(X,Y,U,V,color="C0",angles="xy",
scale_units="xy",scale=5,width=0.015)

plt.show()

在这里插入图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

爱转呼啦圈的小兔子

觉得文章不错?请小编喝杯咖啡吧

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值