matplotlib 单figure多图

method 1

import numpy as np
import matplotlib.pyplot as plt


fg, axes = plt.subplots(1, 2, figsize=(16, 8))
ax1, ax2 = axes
# 或者上两步直接合并成fg, (ax1, ax2) = plt.subplots(1, 1, figsize=(16, 8))
ax1.imshow(np.random.randint(0, 256, size=(100, 100), dtype=np.uint8))
ax1.set_title('img_rand_1')
ax2.imshow(np.random.randint(0, 256, size=(100, 100), dtype=np.uint8))
ax2.set_title('img_rand_2')
plt.show()

method 2

import numpy as np
import matplotlib.pyplot as plt


plt.figure(figsize=(16, 8))
ax1, ax2 = plt.subplot(121), plt.subplot(122)
ax1.imshow(np.random.randint(0, 256, size=(100, 100), dtype=np.uint8))
ax1.set_title('img_rand_1')
ax2.imshow(np.random.randint(0, 256, size=(100, 100), dtype=np.uint8))
ax2.set_title('img_rand_2')
plt.show()
posted @ 2018-06-27 14:57  默盒  阅读(781)  评论(0编辑  收藏  举报