将一个二维数组显示为图片
import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure()
data = np.linspace(0, 1, 40000).reshape(-1, 200)
ax1 = fig.add_subplot(3, 2, 1)
ax1.imshow(data)
ax2 = fig.add_subplot(3, 2, 2)
# show all the color map style: plt.colormaps()
ax2.imshow(data, cmap='hot')
ax3 = fig.add_subplot(3, 2, 3)
# origin default is upper left
ax3.imshow(data, origin='lower', cmap='hot')
ax4 = fig.add_subplot(3, 2, 4)
# scale the coordinates
ax4.imshow(data, cmap='hot', extent=(10, 20, 0, 10))
plt.show()
Figure_1.png
图1使用默认设置,图2自定义了颜色映射,图三将数组的元素从左下角开始放,图4缩放了坐标轴。
网友评论