Python matplotlib:AttributeError:';AxesSubplot';对象没有属性';添加#u轴';

Python matplotlib:AttributeError:';AxesSubplot';对象没有属性';添加#u轴';,python,matplotlib,axes,Python,Matplotlib,Axes,不确定如何修复以下属性错误: 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_

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

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)

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

你的问题没有太多细节,但我敢打赌。 这个错误是不言自明的。无法将
添加_轴
pyplot_2
,因为
pyplot_2
matplotlib.axes.AxesSubplot
对象,并且它们没有定义
添加_轴
方法

只有
matplotlib.figure.figure
对象上定义了
add\u轴
方法

从我对WCSAXS官方文档的简短浏览中得到的信息来看,他们推荐的方法是:

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

只要将matploblit降级到旧版本就可以了。我将其降级为1.4.0,它解决了问题。

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

Axes.set\U color\U cycle(clist)自1.5版起折旧


降低包装等级绝不是解决办法。@yeliabsalohcin如果你愿意,你可以用叉子叉它