Matpltolib自学打卡day4

Matpltlib自学打卡day4

绘制图像

前面我们讲解了如何使用pyplot来画线段图。
今天我们来学习怎样用imshow来画图
import matplotlib.pyplot as plt
import matplotlib.cm as cm
import numpy as np
import matplotlib.cbook as cbook
import matplotlib.path as path
import matplotlib.patches as Pathpatch

np.random.seed(19680801)
# Fixing the seed to reproducibility

delta = 0.025
x = y = np.arange(-3., 3., delta)
X, Y = np.meshgrid(x, y)
Z1 = np.exp(-X**2 - Y**2)
Z2 = np.exp(-(X-1)**2 - (Y-1)**2)
Z = (Z2 - Z1)*2

fig, ax = plt.subplots()
im = ax.imshow(Z, interpolation='bilinear', cmap=cm.RdYlGn, origin='lower', extent=[-3, 3, -3, 3], vmax=abs(Z).max(), vmin=-abs(Z).max())
plt.show()


import matplotlib.pyplot as plt
import matplotlib.cm as cm
import matplotlib.path as path
import matplotlib.patches as Pathpatch
import numpy as np
import matplotlib.cbook as cbook

# A simple image
with cbook.get_sample_data('/Users/menglingpeng/PycharmProjects/pythonProject/demo.jpeg') as image_file:
    image = plt.imread(image_file)  # get the data in the path you gave

fig, ax = plt.subplots()
plt.imshow(image)
plt.axis('off')
plt.title(r'$wife\ of\ menglingpeng$')
# A another image

# datas are 256x256 16bits Integers
w, h = 256, 256
with cbook.get_sample_data('s1045.ima.gz') as data_file:
    s = data_file.read()
A = np.frombuffer(s, np.uint16).astype(float).reshape((w, h))

fig, ax = plt.subplots()
extent = [0, 25, 0, 25]
plt.imshow(A, extent=extent, cmap=plt.cm.hot, origin='lower')
plt.show()

内容有点少,抱歉。
上一篇:【IoT】产品设计:不得不说的「硬件黑话」


下一篇:plt.scatter用法