[英]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.
非常感谢。
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. 您不能将
add_axes
到pyplot_2
因为pyplot_2
是一个matplotlib.axes.AxesSubplot
对象,并且它们没有定义add_axes
方法。
Only matplotlib.figure.Figure
objects have add_axes
method defined on them. 只有
matplotlib.figure.Figure
对象在其上定义了add_axes
方法。
From what I got from a short browse through the WCSAxes official documentation their recommended approach would be: 从我通过WCSAxes官方文档的简短浏览得到的,他们推荐的方法是:
wcs = astropy.wcs.WCS(....)
fig = matplotlib.pyplot.figure()
pyplot_2 = fig.add_subplot(gridspec_layout[2], projection=wcs)
just downgrade matploblit to an old version would help. 只是将matploblit降级为旧版本会有所帮助。 I downgrade it to 1.4.0 and it fix the problem.
我将它降级到1.4.0并解决了问题。
You now need to use set_prop_cycle ie ax.set_prop_cycle(color=['red', 'green', 'blue'])
你现在需要使用set_prop_cycle,即
ax.set_prop_cycle(color=['red', 'green', 'blue'])
Axes.set_color_cycle(clist) was depreciated since, version 1.5. 截至1.5版本,Axes.set_color_cycle(clist)已折旧。
https://matplotlib.org/3.1.0/api/_as_gen/matplotlib.axes.Axes.set_prop_cycle.html https://matplotlib.org/3.1.0/api/_as_gen/matplotlib.axes.Axes.set_prop_cycle.html
I did a conda update pandas<\/code> and the error went away.
我做了一个
conda update pandas<\/code>并且错误消失了。
Nothing else I could find worked.
我找不到其他任何工作。
Mine was a slightly different flavor of this error (not 'add_axes').我的这个错误的风格略有不同(不是'add_axes')。 It happened when I was trying to use pandas.DataFrame.plot within matplotlib subplots.
它发生在我试图在 matplotlib 子图中使用 pandas.DataFrame.plot 时。
I was on pandas 0.25.3 before and after, and a number of packages were upgraded\/downgraded.我之前和之后都在使用 pandas 0.25.3,并且升级\/降级了许多软件包。
"
This is a problem with the Matplotlib package management.这是 Matplotlib 包管理的问题。 I used Anaconda for my python installation.
我使用 Anaconda 进行 python 安装。 So the solution for me was to remove Matplotlib and reinstall it.
所以我的解决方案是删除 Matplotlib 并重新安装它。 Then the error is gone.
然后错误消失了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.