加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

python – plt.figure()vs Matplotlib中的子图

发布时间:2020-12-16 23:00:48 所属栏目:Python 来源:网络整理
导读:在Matplotlib中,许多示例以ax = subplot(111)的形式出现,然后函数应用于ax,如ax.xaxis.set_major_formatter(FuncFormatter(myfunc)). (找到 here) 或者,当我不需要子图时,我可以执行plt.figure(),然后使用plt.plot()或类似函数绘制我需要的任何内容. 现在,我
在Matplotlib中,许多示例以ax = subplot(111)的形式出现,然后函数应用于ax,如ax.xaxis.set_major_formatter(FuncFormatter(myfunc)). (找到 here)

或者,当我不需要子图时,我可以执行plt.figure(),然后使用plt.plot()或类似函数绘制我需要的任何内容.

现在,我正好在第二种情况下,但我想在X轴上调用函数set_major_formatter.在plt上调用它当然不会起作用:

>>> plt.xaxis.set_major_formatter(FuncFormatter(myfunc)) 
Traceback (most recent call last):
File "<stdin>",line 1,in <module> 
AttributeError: 'module' object has no attribute 'xaxis'

我该怎么办?

解决方法

如果选择了您想要的数字,只需使用gca()获取当前轴实例:
ax = gca()
ax.xaxis.set_major_formatter(FuncFormatter(myfunc))

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读