Remove padding from matplotlib plotting

后端 未结 4 1137
心在旅途
心在旅途 2021-02-07 13:24

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         


        
4条回答
  •  眼角桃花
    2021-02-07 13:46

    All previous approaches didn't quite work for me, they all left some padding around the figure.

    The following lines successfully removed the white or transparent padding that was left:

    plt.axis('off')
    ax = plt.gca()
    ax.xaxis.set_major_locator(matplotlib.ticker.NullLocator())
    ax.yaxis.set_major_locator(matplotlib.ticker.NullLocator())
    plt.savefig(IMG_DIR + 'match.png', pad_inches=0, bbox_inches='tight', transparent=True)
    

提交回复
热议问题