【问题标题】:How to fix error running local Otsu threshold example?如何修复运行本地 Otsu 阈值示例的错误?
【发布时间】:2021-05-25 16:54:22
【问题描述】:

我对 Python 很陌生。我正在尝试运行此脚本:

https://scikit-image.org/docs/0.12.x/auto_examples/segmentation/plot_local_otsu.html

但是,我收到了这个错误:

Traceback (most recent call last):
File "/Users/janine/Downloads/plot_local_otsu.py", line 37, in <module>
  fig, ax = plt.subplots(2, 2, figsize=(8, 5), sharex=True, sharey=True,
File "/usr/local/lib/python3.9/site-packages/matplotlib/_api/deprecation.py", line 471, in wrapper
  return func(*args, **kwargs)
File "/usr/local/lib/python3.9/site-packages/matplotlib/pyplot.py", line 1440, in subplots
  axs = fig.subplots(nrows=nrows, ncols=ncols, sharex=sharex, sharey=sharey,
File "/usr/local/lib/python3.9/site-packages/matplotlib/_api/deprecation.py", line 471, in wrapper
  return func(*args, **kwargs)
File "/usr/local/lib/python3.9/site-packages/matplotlib/figure.py", line 908, in subplots
  axs = gs.subplots(sharex=sharex, sharey=sharey, squeeze=squeeze,
File "/usr/local/lib/python3.9/site-packages/matplotlib/gridspec.py", line 307, in subplots
  axarr[row, col] = figure.add_subplot(
File "/usr/local/lib/python3.9/site-packages/matplotlib/figure.py", line 781, in add_subplot
  ax = subplot_class_factory(projection_class)(self, *args, **pkw)
File "/usr/local/lib/python3.9/site-packages/matplotlib/axes/_subplots.py", line 36, in __init__
  self._axes_class.__init__(self, fig, [0, 0, 1, 1], **kwargs)
File "/usr/local/lib/python3.9/site-packages/matplotlib/_api/deprecation.py", line 471, in wrapper
  return func(*args, **kwargs)
File "/usr/local/lib/python3.9/site-packages/matplotlib/axes/_base.py", line 648, in __init__
  self.update(kwargs)
File "/usr/local/lib/python3.9/site-packages/matplotlib/artist.py", line 1064, in update
  ret.append(func(v))
File "/usr/local/lib/python3.9/site-packages/matplotlib/axes/_base.py", line 1531, in set_adjustable
  _api.check_in_list(["box", "datalim"], adjustable=adjustable)
File "/usr/local/lib/python3.9/site-packages/matplotlib/_api/__init__.py", line 126, in check_in_list
  raise ValueError(
    ValueError: 'box-forced' is not a valid value for adjustable; supported values are 'box', 'datalim'

我已经完全按照这里的建议安装了scikit-image:

https://scikit-image.org/docs/stable/install.html.

我在 macOS Mojave 上。

【问题讨论】:

    标签: python matplotlib scikit-image


    【解决方案1】:

    从链接中可以看出,该示例来自skimage 的过时0.12.x 版本,而0.18.0 是当前稳定版本。而且,正如错误消息所示,错误来自这一行:

    fig, ax = plt.subplots(2, 2, figsize=(8, 5), sharex=True, sharey=True,
                           subplot_kw={'adjustable': 'box-forced'})
    

    显然,adjustable 成员的处理方式在 matplotlib.pyplot 中多年来发生了变化。例如,通过简单地删除 subplot_kw 参数,代码运行得非常好:

    fig, ax = plt.subplots(2, 2, figsize=(8, 5), sharex=True, sharey=True)
    

    事实上,这也是skimage 文档中的updated example 的样子(第二个示例)。注意:您必须自己添加两个 import 语句,因为那里给定的代码不完整。

    【讨论】:

    • 非常感谢!我已经从这里下载了脚本:scikit-image.org/docs/stable/_downloads/…,它似乎可以工作(它显示了您链接的页面的所有算法结果)。不过,如何使用自己的图像测试脚本?因为在脚本中从 data.camera() 或 data.page() 获取图像。
    猜你喜欢
    • 2021-08-13
    • 1970-01-01
    • 1970-01-01
    • 2019-03-14
    • 1970-01-01
    • 2019-10-25
    • 2012-10-08
    • 2022-06-22
    • 1970-01-01
    相关资源
    最近更新 更多