python - 多图片背景matplotlib

标签 python image matplotlib background

我需要一些有关 python 绘图的帮助。

我正在使用文档中的一个示例,以便绘制如下所示的内容:

enter image description here

但我现在的问题是,是否可以使用这种样式(方 block )绘制绘图,但在每个方 block 上显示不同的图像。

将从计算机加载我想要显示的图像。

所以,尽可能清楚地说:我想在正方形 0,0 上显示一个图像,在正方形 0,1 上显示一个不同的图像......等等。

最佳答案

一种方法是将图像数组打包到一个大数组中,然后在该大数组上调用 imshow:

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.cbook as cbook
import matplotlib.image as mimage
import scipy.misc as misc
import itertools as IT

height, width = 400, 400
nrows, ncols = 2, 4

# load some arrays into arrs
filenames = ['grace_hopper.png', 'ada.png', 'logo2.png']
arrs = list()
for filename in filenames:
    datafile = cbook.get_sample_data(filename, asfileobj=False)
    arr = misc.imresize(mimage.imread(datafile), (height, width))[..., :3]
    arrs.append(arr)
arrs = IT.islice(IT.cycle(arrs), nrows*ncols)

# make a big array
result = np.empty((nrows*height, ncols*width, 3), dtype='uint8')
for (i, j), arr in IT.izip(IT.product(range(nrows), range(ncols)), arrs):
    result[i*height:(i+1)*height, j*width:(j+1)*width] = arr

fig, ax = plt.subplots()
ax.imshow(result)
plt.show()

enter image description here

关于python - 多图片背景matplotlib,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26234751/

相关文章:

python - Dataframe - 在按日期分组的行中查找第一个 0

python - 使用 node.js pm2 在虚拟环境中运行 python 脚本

python - 创建一个将华氏温度转换为摄氏度的函数

html - 构建 HTML/CSS 页面但无法加载图像

python - 按月分组并绘制一个堆积在 pandas 中的条形图

python pandas indexing matplot 省略图中的一个索引

Python 类给出 "None in the ouptut"

jQuery:如何在大背景图像之前加载显示加载图形,在CSS中设置,加载然后让背景图像淡入?

HTML div 宽度适合图像

python - 如何使用 pyplot.barh() 在每个条上显示条的值