注意
跳转到末尾以下载完整示例代码。
使用关键字绘图#
一些数据结构,例如 dict、结构化 NumPy 数组 或 pandas.DataFrame
,通过字符串索引访问方式(如 data[key]
)提供对标签数据的访问。
对于这些数据类型,Matplotlib 支持通过 data
关键字参数传入整个数据结构,并使用字符串名称作为绘图函数参数,通常您会在这些参数位置传入数据。

import matplotlib.pyplot as plt
import numpy as np
np.random.seed(19680801)
data = {'a': np.arange(50),
'c': np.random.randint(0, 50, 50),
'd': np.random.randn(50)}
data['b'] = data['a'] + 10 * np.random.randn(50)
data['d'] = np.abs(data['d']) * 100
fig, ax = plt.subplots()
ax.scatter('a', 'b', c='c', s='d', data=data)
ax.set(xlabel='entry a', ylabel='entry b')
plt.show()