matplotlib:AttributeError:'AxesSubplot'对象没有属性'add_axes' [英] matplotlib: AttributeError: 'AxesSubplot' object has no attribute 'add_axes'
问题描述
不确定如何修复以下属性错误:
Not sure exactly sure how to fix the following attribute error:
AttributeError: 'AxesSubplot' object has no attribute 'add_axes'
问题似乎与我设置情节的方式有关:
The offending problem seems to be linked to the way I have set up my plot:
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)
有人知道如何解决这个问题吗?非常感谢.
Does anybody know how to solve this? Many thanks.
推荐答案
在您的问题中没有太多细节可做,但我会猜测.该错误是不言自明的.你不能 add_axes
到 pyplot_2
因为 pyplot_2
是一个 matplotlib.axes.AxesSubplot
对象,而他们没有定义了 add_axes
方法.
There's not much details to go on in your question but I'll wager a guess.
The error is pretty self-explanatory. You can't add_axes
to pyplot_2
because pyplot_2
is a matplotlib.axes.AxesSubplot
object and they don't have an add_axes
method defined.
只有 matplotlib.figure.Figure
对象具有在其上定义的 add_axes
方法.
Only matplotlib.figure.Figure
objects have add_axes
method defined on them.
根据我从WCSAxes官方文档的简短浏览中获得的结果,他们推荐的方法是:
From what I got from a short browse through the WCSAxes official documentation their recommended approach would be:
wcs = astropy.wcs.WCS(....)
fig = matplotlib.pyplot.figure()
pyplot_2 = fig.add_subplot(gridspec_layout[2], projection=wcs)
这篇关于matplotlib:AttributeError:'AxesSubplot'对象没有属性'add_axes'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!