matplotlib.pyplot 文档说它是 matplotlib 的基于状态的接口.什么是基于状态的接口? [英] matplotlib.pyplot documentation says it is state-based interface to matplotlib. What is state-based interface?

查看:28
本文介绍了matplotlib.pyplot 文档说它是 matplotlib 的基于状态的接口.什么是基于状态的接口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Matplotlib的 pyplot 文档说如下,

Matplotlib's pyplot documentation says as follow,

pyplot matplotlib.pyplot是matplotlib的基于状态的接口.

pyplot matplotlib.pyplot is a state-based interface to matplotlib.

基于状态的接口到 matplotlib 的含义

What is meant by state-based interface to matplotlib

推荐答案

pyplot 教程中 它说

在matplotlib.pyplot中,函数调用会保留各种状态,以便跟踪当前图形和绘图区域之类的东西,并将绘图函数定向到当前轴

In matplotlib.pyplot various states are preserved across function calls, so that it keeps track of things like the current figure and plotting area, and the plotting functions are directed to the current axes

例如:

import matplotlib.pyplot as plt
plt.plot([1,2,3],[4,6,5])

这会将pyplot置于定义了当前图形和当前轴的状态.随后发出一些其他 pyplot 命令,如

This puts pyplot in a state where a current figure and a current axes is defined. Subsequently issuing some other pyplot command like

plt.title("My title")

将设置存储在 pyplot 状态中的当前轴的标题.最后,

will set the title of the current axes that is stored in the pyplot state. Finally,

plt.show()

将显示存储在 pyplot 状态中的所有数字.(也相关: plt.show()如何知道要显示什么?)

will show all the figures stored in the pyplot state. (Also relevant: How does plt.show() know what to show?)

因此,总的来说,基于状态的接口意味着pyplot具有几个函数,这些函数将作用于当前定义的状态.这与使用对象方法的面向对象方法有着根本的不同:​​

So in total, the state-based interface means that pyplot has a couple of functions, which will act on a currently defined state. This is fundamentally different to an object-oriented approach, where object methods are used:

import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot([1,2,3],[4,6,5])
ax.set_title("My Title")

在这里,不同对象的方法用于创建新内容.(仍然可以通过pyplot创建该图,以便最终可以通过 plt.show()进行显示.)

Here, different objects' methods are used to create new content. (Still the figure is created via pyplot, such that it can eventually be shown via plt.show().)

这篇关于matplotlib.pyplot 文档说它是 matplotlib 的基于状态的接口.什么是基于状态的接口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆