【问题标题】:matplotlib: AttributeError: 'AxesSubplot' object has no attribute 'add_axes'matplotlib:AttributeError:“AxesSubplot”对象没有属性“add_axes”
【发布时间】:2016-10-13 07:15:18
【问题描述】:

不确定如何修复以下属性错误:

AttributeError: 'AxesSubplot' object has no attribute 'add_axes'

这个问题似乎与我设置情节的方式有关:

gridspec_layout = gridspec.GridSpec(3,3)
pyplot_2 = fig.add_subplot(gridspec_layout[2])

ax = WCSAxes(fig, [0.1, 0.1, 0.8, 0.8], wcs=wcs)
pyplot_2.add_axes(ax)

有人知道如何解决这个问题吗?非常感谢。

【问题讨论】:

    标签: python matplotlib axes


    【解决方案1】:

    我做了一个conda update pandas 并且错误消失了。我找不到其他任何方法。

    我的这个错误的风格略有不同(不是“add_axes”)。当我尝试在 matplotlib 子图中使用 pandas.DataFrame.plot 时发生这种情况。

    我之前和之后都在pandas 0.25.3上,升级/降级了很多包。

    【讨论】:

      【解决方案2】:

      您现在需要使用 set_prop_cycle 即ax.set_prop_cycle(color=['red', 'green', 'blue'])

      Axes.set_color_cycle(clist) 从 1.5 版开始贬值。

      https://matplotlib.org/3.1.0/api/_as_gen/matplotlib.axes.Axes.set_prop_cycle.html

      【讨论】:

        【解决方案3】:

        只需将 matploblit 降级到旧版本会有所帮助。我将它降级到 1.4.0 并解决了问题。

        【讨论】:

        • 降级软件包永远不是解决方案。
        • @yeliabsalohcin 如果你愿意,你可以分叉它
        【解决方案4】:

        您的问题没有太多详细信息,但我敢打赌。 这个错误是不言自明的。你不能 add_axespyplot_2 因为 pyplot_2 是一个 matplotlib.axes.AxesSubplot 对象并且他们没有定义 add_axes 方法。

        只有matplotlib.figure.Figure 对象定义了add_axes 方法。

        根据我对 WCSAxes 官方文档的简短浏览,他们推荐的方法是:

        wcs = astropy.wcs.WCS(....)
        fig = matplotlib.pyplot.figure()
        pyplot_2 = fig.add_subplot(gridspec_layout[2], projection=wcs)
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2019-04-22
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2017-02-13
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多