在Matplotlib中,许多示例以形式出现ax = subplot(111),然后应用函数ax,例如ax.xaxis.set_major_formatter(FuncFormatter(myfunc)). (在这里找到)
或者,当我不需要子图时,我可以做plt.figure(),然后用plt.plot()或类似的功能绘制我需要的任何东西。
现在,我正好是第二种情况,但我想set_major_formatter在 X 轴上调用函数。调用它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'
我应该在这里做什么?