Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Matplotlib plt.xlabel()与ax.setxlabel()的比较_Python_Oop_Matplotlib - Fatal编程技术网

Python Matplotlib plt.xlabel()与ax.setxlabel()的比较

Python Matplotlib plt.xlabel()与ax.setxlabel()的比较,python,oop,matplotlib,Python,Oop,Matplotlib,我使用的一些代码在Python中使用matplotlib的单例版本,即它有如下调用 plt.figure() ... plt.xlabel("abc") 我正在尝试将其转换为功能性/无内存版本: fig,ax = plt.subplots() ... ax.set_xlabel("abc") 有几个问题: 是否有直接设置轴的xlabel的选项?某物 像ax.xlabel=“xlabel string” (不是 即使是我们可以设置的私有属性) 还是总是需要通过setter?这一直是 把我弄糊

我使用的一些代码在Python中使用matplotlib的单例版本,即它有如下调用

plt.figure()
...
plt.xlabel("abc")
我正在尝试将其转换为功能性/无内存版本:

fig,ax = plt.subplots()
...
ax.set_xlabel("abc")
有几个问题:

  • 是否有直接设置轴的xlabel的选项?某物 像ax.xlabel=“xlabel string”

  • (不是 即使是我们可以设置的私有属性)

  • 还是总是需要通过setter?这一直是 把我弄糊涂了,觉得我不是蟒蛇

  • 为什么API从
    plt.xlabel()
    更改为
    ax.set\xlabel()


Matplotlib拥有pyplot接口,然后开发了面向对象接口,如文档()所述


后者现在是首选,所以使用fig,ax=plt.subplot,然后在ax上使用setter方法。

有趣的是,你知道他们为什么决定更改API吗?