我正在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(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()
尝试使用
pad_inches=0
,即从documentation:
我认为默认值是
pad_inches=0.1
这对我有效。绘制后,使用ax=plt.gca()从plt获取Axes对象。然后设置ax对象的xlim和ylim以匹配图像宽度和图像高度。绘图时,Matplotlib似乎会自动增加查看区域的xlim和ylim。请注意,设置y_lim时,必须反转坐标顺序。
以前的方法对我来说都不太管用,都在图上留下了一些空白。
以下行成功地删除了剩余的白色或透明填充:
相关问题 更多 >
编程相关推荐