[英]Trying to display images with PIL and BytesIO but returns nothing
我正在尝试显示数据集中的徽标。 数据集如下所示:
Player Club Logo
tom https://abc.png
jerry https://def.png
peter https://frf.png
woody https://awt.png
但是,它没有给我任何标志。 它只显示了 4 个空的网格框。 我的代码如下。 我也尝试使用im = Image.open(BytesIO(r.content)).show()
但徽标最终在我的计算机上打开。
import matplotlib.pyplot as plt
import requests
from PIL import Image
from io import BytesIO
fig, ax = plt.subplots(2,2, figsize=(2,2))
for i in range(4):
r = requests.get(df['Club Logo'][i])
im = Image.open(BytesIO(r.content))
plt.show()
谢谢
从这些图像开始:
"0.png"
:
"1.png"
:
"2.png"
:
"3.png"
:
我想你想要这个:
#!/usr/bin/env python3
from PIL import Image
import numpy as np
import matplotlib.pyplot as plt
fig, ax = plt.subplots(2,2, figsize=(2,2))
for i in range(4):
# Load image and make into Numpy array
im = Image.open(f'{i}.png').convert('RGB')
na = np.array(im)
# Shove into the plot
ax[i%2][i//2].imshow(na)
fig.show()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.