python如何在第一个p的左边设置绘图

2024-09-29 23:16:20 发布

您现在位置:Python中文网/ 问答频道 /正文

我试着画两个不同的图,一个在另一个的左边,我试着用matplot的sublot,但是它把second图放下来了,另一个我怀疑我用错了子图,这是我的代码

# Create bars

from matplotlib.pyplot import figure
bar = plt.figure(figsize=(10,5))
plt.subplot(121)
plt.barh(plottl['Nombres'] ,plottl['Probas'])
presunto= plt.figure(figsize=(10,10))
presunto = plt.subplot(122)
img=mpimg.imread((predict+names[0]+ '/'+ onlyfiles[0]))
mgplot = plt.imshow(img)

plt.show()
predictions=[]

这是一张照片。正在发生的事情

enter image description here

我希望你能帮我解决这个问题,提前谢谢大家

编辑:我把照片放在这里

enter image description here


Tags: 代码imgcreateplt照片figuresecondbars
2条回答

您正在创建2个图形,而不是2个子图,不过当您想要绘制不同大小的子图时,最好使用gridspec。看this link

from matplotlib.pyplot import figure
bar = plt.figure(figsize=(10,5))
plt.subplot(121)
plt.barh(plottl['Nombres'] ,plottl['Probas'])

presunto = plt.subplot(122)
img=mpimg.imread((predict+names[0]+ '/'+ onlyfiles[0]))
mgplot = plt.imshow(img,aspect="auto")

plt.show()

您正在创建2个图形,而不是一个具有2个子图的图形。删除行presunto= plt.figure(figsize=(10,10)),它应该可以工作

相关问题 更多 >

    热门问题