【发布时间】:2019-07-02 08:19:38
【问题描述】:
其他人也有这个问题,我用了他们的解决方案但没有解决。
我使用virtual env with python3.5。
Matplotlib 安装在 virtual env 下。
我在系统上安装了 python3.tkinter。
当我检查时
matplotlib.get_backend()
我有
>>> import matplotlib
>>> matplotlib.get_backend()
'TkAgg'
但是当我运行下面的代码时
for image_path in TEST_IMAGE_PATHS:
image = Image.open(image_path)
# the array based representation of the image will be used later in order to prepare the
# result image with boxes and labels on it.
image_np = load_image_into_numpy_array(image)
# Expand dimensions since the model expects images to have shape: [1, None, None, 3]
image_np_expanded = np.expand_dims(image_np, axis=0)
# Actual detection.
output_dict = run_inference_for_single_image(image_np, detection_graph)
# Visualization of the results of a detection.
vis_util.visualize_boxes_and_labels_on_image_array(
image_np,
output_dict['detection_boxes'],
output_dict['detection_classes'],
output_dict['detection_scores'],
category_index,
instance_masks=output_dict.get('detection_masks'),
use_normalized_coordinates=True,
line_thickness=8)
#plt.figure(figsize=IMAGE_SIZE)
plt.imshow(image_np)
plt.show()
我有问题
UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.
% get_backend())
我把标题作为
from io import StringIO
import matplotlib
matplotlib.rcParams["backend"] = "TkAgg"
from matplotlib import pyplot as plt
from PIL import Image
有人说已经解决了,但我还是有同样的问题,plt 不显示图片。
【问题讨论】:
-
你的警告不是很清楚吗?您需要使用 GUI 类型的后端来获取带有
show()的图像。你在什么系统上? -
Ubuntu 16.04。这是警告。但问题是图像不显示。
-
你如何执行你的程序?哪个python命令?
which python3的结果是什么?如果将matplotlib.rcParams["backend"] = "TkAgg"替换为matplotlib.use("TkAgg")会怎样? -
@PierredeBuyl
which python3给了我/home/cnv/venvpy3_cpu/bin/python3.matplotlib.use("TkAgg")仍然有相同的警告并且没有图像显示。
标签: python matplotlib tkinter