python - How to fix error running local Otsu threshold example?
问题描述
I am very new to Python. I am trying to run this script:
https://scikit-image.org/docs/0.12.x/auto_examples/segmentation/plot_local_otsu.html
But, I'm getting this error:
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'
I have installed scikit-image
exactly as recommended here:
https://scikit-image.org/docs/stable/install.html.
I am on macOS Mojave.
解决方案
As you can see from the link, the example is from the outdated 0.12.x
version(s) of skimage
, whereas 0.18.0
is current stable version. And, as the error message indicates, the error comes from this line:
fig, ax = plt.subplots(2, 2, figsize=(8, 5), sharex=True, sharey=True,
subplot_kw={'adjustable': 'box-forced'})
Obviously, the handling of the adjustable
member has changed in matplotlib.pyplot
over the years. By simply removing the subplot_kw
parameter at all, for example, the code runs perfectly fine:
fig, ax = plt.subplots(2, 2, figsize=(8, 5), sharex=True, sharey=True)
In fact, that's also, what the updated example from the skimage
documentation looks like (second example there). Notice: You'll have to add two import
statements on your own, since the given code there in incomplete.
推荐阅读
- dask - 如何使用 dask_ml 运行 PCA。我收到错误消息,“此函数 (tsqr) 在高瘦矩阵的情况下支持 QR 分解”?
- swift - 访问类实例外部的泛型类类型
- python - x轴上重叠字符串的解决方案需要很长时间才能绘制
- android - Android 上受信任的 Web 活动不隐藏 URL 栏
- r - 将日期添加到向量的第一个元素以获取新日期,然后添加下一个元素以生成新日期,依此类推
- java - Java - 双链表实现
- mediawiki - 使用 css/html 下拉菜单作为 Mediawiki 模板
- codenameone - 代号一中视频的后台播放
- typescript - 如何使用 Typescript AST 使用初始化程序创建导出的常量?
- javascript - 在移动设备上将班级转移到另一个班级