【问题标题】:Can't inline plot inset_axes in Jupyter Notebook无法在 Jupyter Notebook 中内联绘图 inset_axes
【发布时间】:2018-11-27 14:38:21
【问题描述】:

我目前正在尝试在 Jupyter Notebook 中将插入轴绘制到 matplotlib 图中,但我总是收到以下错误:

TypeError: get_tightbbox() got an unexpected keyword argument 'bbox_extra_artists'

最小的工作示例:

%matplotib inline
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1.inset_locator import inset_axes
import numpy as np

fig, axis = plt.subplots(1, 1)
axis.imshow(np.random.rand(5, 5))
ins_axes = inset_axes(axis, width=0.75, height=0.75, loc=1)

如果我将代码作为脚本运行或不使用%matplotlib inline,这就是输出的样子:

expected output

我的 matplotlib 版本是 3.0.1,jupyter 是 1.0.0,Python 是 3.6.7。

我最近从 matplotlib 1 升级,一切正常。

编辑:matplotlib 3.0.0 导致另一个错误更早出现:

AttributeError: module 'matplotlib' has no attribute 'artist'

EDIT2:升级到 matplotlib 3.0.2 成功了,请参阅 ImportanceOfBeingErnest's 答案!

【问题讨论】:

    标签: python-3.x matplotlib plot jupyter-notebook


    【解决方案1】:

    这是 matplotlib 3.0.1 中的 a bug,由 FIX: allow non bbox_extra_artists calls #12635 修复。

    您需要更新到 matplotlib 3.0.2 或降级到 3.0.0。

    【讨论】:

    • 这确实是我遇到的bug!升级到 3.0.2 修复它,非常感谢!
    【解决方案2】:

    对我来说效果很好。 使用 matplotlib 3.0.0。这可能是较新/较旧版本的问题吗?

    【讨论】:

    • 3.0.0 对我不起作用(请参阅上面的编辑),接下来我会尝试更高版本!
    猜你喜欢
    • 2021-11-15
    • 2016-08-05
    • 2018-01-10
    • 1970-01-01
    • 2018-12-10
    • 1970-01-01
    • 2018-08-25
    • 1970-01-01
    • 2019-03-22
    相关资源
    最近更新 更多