Python中的 Matplotlib.artist.Artist.format_cursor_data()
Matplotlib是Python中的一个库,它是 NumPy 库的数值数学扩展。 Artist 类包含呈现为 FigureCanvas 的对象的 Abstract 基类。图中所有可见元素都是 Artist 的子类。
matplotlib.artist.Artist.format_cursor_data() 方法
matplotlib 库的 Artist 模块中的 format_cursor_data () 方法用于获取数据的字符串表示形式。
Syntax: Artist.remove_callback(self, data)
Parameters: This method accepts the following parameters.
- data: This parameter is the data which is used to be used.
Returns: This method returns the string representation of data.
以下示例说明了 matplotlib 中的 matplotlib.artist.Artist.format_cursor_data()函数:
示例 1:
# Implementation of matplotlib function
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.artist import Artist
np.random.seed(10**7)
geeksx = np.random.randn(10)
fig, ax = plt.subplots()
ax.plot(geeksx)
ax.text(1.5, 0.85,
"Value return by format_cursor_data():",
fontweight ="bold")
ax.text(0, 0.7,
Artist.format_cursor_data(ax, data = geeksx))
fig.suptitle('matplotlib.artist.Artist.format_cursor_data()\
function Example', fontweight ="bold")
plt.show()
输出:
示例 2:
# Implementation of matplotlib function
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.artist import Artist
geeksx = np.array([24.40, 110.25, 20.05,
22.00, 61.90, 7.80,
15.00])
fig, ax = plt.subplots()
ax.plot(geeksx, 'go-')
ax.text(1, 95,
"Value return by format_cursor_data():",
fontweight ="bold")
ax.text(1.3, 85,
Artist.format_cursor_data(ax,
data = geeksx))
fig.suptitle('matplotlib.artist.Artist.format_cursor_data()\
function Example', fontweight ="bold")
plt.show()
输出: