matplotlib:AttributeError:'AxesSubplot'对象没有属性'add_axes'

7 python axes matplotlib

不完全确定如何解决以下属性错误:

AttributeError: 'AxesSubplot' object has no attribute 'add_axes'
Run Code Online (Sandbox Code Playgroud)

令人讨厌的问题似乎与我设定情节的方式有关:

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)
Run Code Online (Sandbox Code Playgroud)

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

The*_*erd 6

您现在需要使用 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


lje*_*ibo 5

你的问题没有太多细节,但我敢打赌。这个错误是不言自明的。你不能add_axes这样做pyplot_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)
Run Code Online (Sandbox Code Playgroud)