Я пытаюсь автоматически сохранить фигуру, сгенерированную scikit-image try_all_threshold
.
MWE:
#! /usr/bin/env python
import sys
import os
from pathlib import Path
import numpy
import skimage
from skimage import color, filters, io
import matplotlib as mpl
from matplotlib.figure import Figure
import matplotlib.pyplot as plt
skimage.io.use_plugin("pil")
mpl.rcParams["font.family"] = ["sans-serif"]
mpl.rcParams["font.sans-serif"] = ["Linux Biolinum"]
mpl.rcParams["axes.titlesize"] = "medium"
def analyze(files):
for index, file in enumerate(files):
print("Analyzing {0}, please wait...".format(file))
try:
image = io.imread(file)
except ValueError as error:
print("Error when loading image, skipping: {0}".format(error))
continue
luma = color.rgb2gray(image)
# Threshold the image to obtain the reference borders
fig, ax = filters.try_all_threshold(
luma, figsize=(1, 2), verbose=False)
plt.show()
fig.savefig("test.png")
def main():
if len(sys.argv) > 1:
files = [path for path in sys.argv[1:] if Path(path).exists()]
if len(files) == 0:
print("No images to slice.")
else:
print("Found {0} images to slice.".format(len(files)))
analyze(files)
if __name__ == "__main__":
main()
Вывод содержит много отступов, которые я должен удалить:
Я пытался использовать bbox_inches='tight', pad_inches=0
, как предлагалось в других ответах, но безрезультатно.
Чего не хватает для matplotlib, чтобы удалить все отступы?