简体   繁体   English

"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.非常感谢。

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_axespyplot_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.

相关问题 AttributeError: 'AxesSubplot' object 没有属性 'Circle' 在 tkinter 中嵌入 matplotlib - AttributeError: 'AxesSubplot' object has no attribute 'Circle' Embedding matplotlib in tkinter AttributeError:模块“matplotlib”没有属性“AxesSubplot” - AttributeError: module 'matplotlib' has no attribute 'AxesSubplot' 有一个类 matplotlib.axes.AxesSubplot,但是模块 matplotlib.axes 没有属性 AxesSubplot - There is a class matplotlib.axes.AxesSubplot, but the module matplotlib.axes has no attribute AxesSubplot AttributeError:“AxesSubplot”对象没有属性“海岸​​线” - AttributeError: 'AxesSubplot' object has no attribute 'coastlines' 用add_axes保存matplotlib图 - Saving matplotlib figure with add_axes AttributeError: 'AxesSubplot' object 没有属性 'get_xtickabels' - AttributeError: 'AxesSubplot' object has no attribute 'get_xtickabels' 子图AttributeError:&#39;AxesSubplot&#39;对象没有属性&#39;get_extent&#39; - subplot AttributeError: 'AxesSubplot' object has no attribute 'get_extent' Tkinter AttributeError: 'AxesSubplot' object has no attribute 'canvas' and matplotlib graphs don't update until I resize the tkinter window - Tkinter AttributeError: 'AxesSubplot' object has no attribute 'canvas' and matplotlib graphs don't update until I resize the tkinter window 轴不与 add_axes 一起显示 - axes are not displayed with add_axes 'AxesSubplot' 对象没有属性 'colorbar' - 'AxesSubplot' object has no attribute 'colorbar'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM