Remove padding from matplotlib plotting

后端 未结 4 936
心在旅途
心在旅途 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:58

    This worked for me. After plotting, get the Axes object from plt using ax = plt.gca(). Then set the xlim, and ylim of ax object to match image width and image height. Matplotlib seems to automatically increase xlim and ylim of viewing area when you plot. Note that while setting y_lim you have to invert the order of coordinates.

    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')
    ax = plt.gca();
    ax.set_xlim(0.0, width_of_im);
    ax.set_ylim(height_of_im, 0.0);
    plt.savefig( IMG_DIR + 'match.png',bbox_inches='tight', transparent="True")
    

提交回复
热议问题