从matplotlib绘图中删除填充 [英] Remove padding from matplotlib plotting

查看:369
本文介绍了从matplotlib绘图中删除填充的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在matplotlib中绘制一个图像,它不断给我一些填充。这是我试过的:

  def field_plot():
x = [i [0] for i in path ]
y = [i [1] for i in path]
plt.clf()
plt.axis([0,560,0,820])
im = plt .imread('field.jpg')
field = plt.imshow(im)
for i in range(len(r)):
plt.plot(r [i] [0 ],r [i] [1],c =(rgb_number(velocity [i]),0,1-rgb_number(velocity [i])),linewidth = 1)
plt.axis('off'
plt.savefig(IMG_DIR +'match.png',bbox_inches ='tight',transparent =True)
plt.clf()
pre>

解决方案

尝试使用 pad_inches = 0 ,即

  plt.savefig(IMG_DIR +'match.png',bbox_inches ='tight',transparent =True,pad_inches = 0)

文档


pad_inches:当bbox_inches为$时,数字的填充量b $ b'tight'。


我认为默认值是 pad_inches = 0.1


I am plotting an image in matplotlib, and it keeps giving me some padding. This is what I have tried:

def field_plot():
    x = [i[0] for i in path]
    y = [i[1] for i in path]
    plt.clf()
    plt.axis([0, 560, 0, 820])
    im = plt.imread('field.jpg')
    field = plt.imshow(im)
    for i in range(len(r)):
        plt.plot(r[i][0],r[i][1],c=(rgb_number(speeds[i]),0,1-rgb_number(speeds[i])),linewidth=1)
    plt.axis('off')
    plt.savefig( IMG_DIR + 'match.png',bbox_inches='tight', transparent="True")
    plt.clf()

解决方案

Try using pad_inches=0, i.e.

plt.savefig( IMG_DIR + 'match.png',bbox_inches='tight', transparent="True", pad_inches=0)

From the documentation:

pad_inches: Amount of padding around the figure when bbox_inches is ‘tight’.

I think the default is pad_inches=0.1

这篇关于从matplotlib绘图中删除填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆